Jump to content

Checking Status Of Modem


Recommended Posts

Hi,

I'm trying to make a script to check the status of my modem if it is connected LAN before accessing it..I tried this script but still I can't make it to work as if..

CheckRouter()  ;check if router is connected


Func CheckRouter()
   
$router = Ping("192.168.10.1",750)  ;ping modem
If $Router = 0 then                 ;if no response
Delay5Sec()                         ;call delay routine to wait more time for the modem to stabilized..

else                                ;if connected

LoadModem()                         ;call modem page

Endif

EndFunc


Func Delay5Sec()
   Sleep(5000)
   CheckRouter()
EndFunc


Func LoadModem()

Local  $oIE = _IECreate("http://192.168.10.1/pageinfo.html",0,1,1,0)    

; some code here...

EndFunc

But I often end up to "Page Not Found" on the browser...

 

Any help will be appreciated..

 

TIA

Edited by Hodahel
Link to comment
Share on other sites

Hi,

No I can't access the modem manually, since my network connection at the task bar show no LAN connected yet..

When I first turn on my modem, it takes about 2-6 minutes before it is detected by my PC, so I need a script to ping the modem and don't wait for that constant 6 minutes if it's already connected in just 3 minutes..

Link to comment
Share on other sites

You should know one thing about that script, it's recursing between 2 functions constantly, if you run it long enough the script will crash with a recursion level reached error. 

By recursing I mean that one function is calling another function which in turn calls the function that calls it. 

Delay5Sec()  is called by CheckRouter(), after the 5 second delay Delay5Sec() calls CheckRouter() and so on and so on.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

So what is the best way you can recommend?

I tried this script as DatMCEyeBall posted.

ConsoleWrite("Internet Is Connected" & " = " & _IsInternetConnected() & @CRLF) ; ( Returns "True" Or "False" )
 
Func _IsInternetConnected()
    Local $aReturn = DllCall('connect.dll', 'long', 'IsInternetConnected')
    If @error Then
        Return SetError(1, 0, False)
    EndIf
    Return $aReturn[0] = 0
EndFunc   ;==>_IsInternetConnected

But I have no idea if it is checking by Internet connectivity or just querying a modem? Since I don't need to connect to internet just query the modem if online or not..

Link to comment
Share on other sites

  • 3 months later...

The .dll call monitors the status of the internet connection as determined by Windows itself.

How Windows determines if it is online (or not) is rather simple, though works very well.  Basically, they constantly probe a given page on the Internet and if the return is correct (it is a page with very little in it so it keeps down bit transfer), your computer (and thus, the .dll quoted to you) will show 'online'.

Here's a Microsoft doc about it (though, as with most of their docs, don't expect to much detail....)

http://msdn.microsoft.com/en-us/library/ee264321(v=vs.85).aspx

and, here's a link to a page where I learned a lot about the inner workings of this feature

http://superuser.com/questions/277923/how-does-windows-know-whether-it-has-internet-access-or-if-a-wi-fi-connection-re

I had a need (or was that a desire...?) for a 'better than' way to detect status and came up with two variations - both work to detect online status changes, and both much faster than the reporting done by the .dll, though do more 'work' (overhead, resources, etc.) than needed for most applications (the .dll method is the prefered one)

This one is for notifying you if the IP address has changed - in my application it is critical to keep the same one or restart the app (there is no work-around I could find, which is one reason I have abandoned the technology used in that app and moved into more AutoIt creations).  I ran this in the While loop and it works well - and very fast - reporting long before the 'offline' notification.

Local $IPnow = @IPAddress1
If $IP <> $IPnow  And $IP <> "127.0.0.1" And $showing <> 1 Then
 SplashTextOn("IP ADDRESS CHANGE",@CRLF &  "The IP address for this computer has changed." & @CRLF & @CRLF & "Expecting " & $IP  & @CRLF & "Current IP " & $IPnow  & @CRLF &  @CRLF & "Check Your Internet Connection.  " & @CRLF & "You may have to restart the program. ")
 $showing = 1
EndIf
If $showing = 1 And $IP <> $IPnow  And $IP <> "127.0.0.1:4001"  Then
 Sleep(100)
 ControlSetText("IP ADDRESS CHANGE", "", "Static1", @CRLF & "The IP address for this computer has changed." & @CRLF & @CRLF & "Expecting " & $IP  & @CRLF & "Current IP " & $IPnow  & @CRLF &  @CRLF & "Check Your Internet Connection.  " & @CRLF & "You may have to restart Karaoke Pro Tools. ")
EndIf
If $IP = $IPnow  Then
 SplashOff()
 $showing = 0
EndIf

A more to-the-point way of doing what Microsoft does (basically duplicating the internal workings of the online status indicator in your PC, but it is faster reporting if you keep it in a moderately tight {Sleep (500) is what I've used} loop....) as described in the above documents - and may be a way you are looking for (somewhat) as what it does is to directly check the active webpage on the Internet.

Func _online_status()
    Local $status = 0
    If @IPAddress1 <> "127.0.0.1" Then
        Local $oIE = _IECreate("http://www.msftncsi.com/ncsi.txt", 0, 0, 1, 0)
        Local $sText = _IEBodyReadText($oIE)
        If $sText = "Microsoft NCSI" Then
            $status = 1
        EndIf
        _IEQuit($oIE)
    EndIf
    Return $status
EndFunc   ;==>_online_status

Of course, you really should not use MS page for this - though, if it is an occasional test, I doubt their hit counters will go too wild......  If you are running this in a released-to-the-public program, you might want to consider making your own web page for it (and putting your own counter on it so you can see how much your program is used......)

Again, though, the 'prefered' method of checking is the one you have been given (the .dll), though, now, you understand why/how it works!

Link to comment
Share on other sites

In my opinion you should just be able to query the return of @IpAddress1, Which should be your assigned lan address. Then check it to see if it's a valid address. Below is an example;

$IsConnected = @IpAddress1

While 1
   If StringInStr("" & $IsConnected & "", "0.0.0.0") <> "0" Then
      MsgBox(0, "Connection Test", "Not Connected to LAN")
      Sleep("5000")
   ElseIf StringInStr("" & $IsConnected & "", "169") <> "0" Then
      MsgBox(0, "Connection Test", "Not Connected to LAN")
      Sleep("5000")
   ElseIf StringInStr("" & $IsConnected & "", "192") <> "0" Then
      MsgBox(0, "Connection Test", "Connected to LAN")
      Call("function")
      ExitLoop
   EndIf
WEnd

Let me know what you guys think.. You can furthermore modify this to check for Internet Connectivity by using _GetIP.

Edited by BlackDawn187
Link to comment
Share on other sites

Simply checking the IP is one way of testing, though here's a scenario that I ran into that required me to learn (and do) more........

Connect to the internet through a router (wireless is typical, though LAN is just as good)

Now, you will have an IP of 192.x.x.x (or perhaps 10.x.x.x - or you could have anything the router will allow....)

Disconnect the Internet cable from the router (i.e., not the computer from the router)

Check your IP - yep, it is still the same - though you are NOT connected to the internet.

So, your StringInStr method is 'ok', though not complete enough.   (and, we both need to change our code to reflect the other's local IP - I didn't run into the 169.x.x.x one, but it is certainly as valid a 'problem' as 127.x.x.x {and I don't recall what situation you can have 0.0.0.0 though not a bad thing to check for} - which is another reason the .dll is a 'better' solution for most applications)

Link to comment
Share on other sites

Simply checking the IP is one way of testing, though here's a scenario that I ran into that required me to learn (and do) more........

Connect to the internet through a router (wireless is typical, though LAN is just as good)

Now, you will have an IP of 192.x.x.x (or perhaps 10.x.x.x - or you could have anything the router will allow....)

Disconnect the Internet cable from the router (i.e., not the computer from the router)

Check your IP - yep, it is still the same - though you are NOT connected to the internet.

So, your StringInStr method is 'ok', though not complete enough.   (and, we both need to change our code to reflect the other's local IP - I didn't run into the 169.x.x.x one, but it is certainly as valid a 'problem' as 127.x.x.x {and I don't recall what situation you can have 0.0.0.0 though not a bad thing to check for} - which is another reason the .dll is a 'better' solution for most applications)

The best way to address the issue of a cable being unplugged would be to toss the @IPAddress1 macro inside the While statement to check/update it frequently. Though not too frequently as to consume unnecessary resources. There's a couple other private ranges you left out that routers can use, But the OP should do some R&D if s/he is unaware of them. I merely laid the concrete for him/her to build from. @TechCoder - Interesting scenario you've provided ;)

Alternatively, You could _RunDos("IpConfig /all") & print the result to a text file to search for disconnected adapters.

Link to comment
Share on other sites

IPCONFIG and @IPADDRESS won't tell you when the router is not connected to the internet, which is what TechCoder just said. _GetIP will tell you if you're off line because it will fail to find your external IP address.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...