Sign in to follow this  
Followers 0
storme

Dial-up or permanent connection - detect and use.

5 posts in this topic

G'day all

I'm working on making self updating scripts, the computers I work on are standalone on-site domestic. Most have permanent connections but some use dial-up or ad-hoc non-permanent wireless connections.

SO the scripts will have to work in a totally NON-Standard environment

and

(if Possible) work out what that environment is.

(IF NOT Possible) then I'll have to resort to an INI file to flag type of connection.

If I just put in the standard update that checks for a file on some server the script will trigger the dial-up every time it's run and annoy the customer. :)

I'm hoping that someone has already created a UDF or has something that maybe close.

I did write up some steps I was going to try but went around in circles, gave up and deleted the lot in disgust.

Hope someone can help or at least point me in a useful direction.

Thanks for all/any help

John Morrison

Share this post


Link to post
Share on other sites



storme

$connect = _GetNetworkConnect()

If $connect Then
    MsgBox(64, "Connections", $connect)
Else
    MsgBox(48, "Warning", "There is no connection")
EndIf

Func _GetNetworkConnect()
    Local Const $NETWORK_ALIVE_LAN = 0x1  ;net card connection
    Local Const $NETWORK_ALIVE_WAN = 0x2  ;RAS (internet) connection
    Local Const $NETWORK_ALIVE_AOL = 0x4  ;AOL
    
    Local $aRet, $iResult
    
    $aRet = DllCall("sensapi.dll", "int", "IsNetworkAlive", "int*", 0)
    
    If BitAND($aRet[1], $NETWORK_ALIVE_LAN) Then $iResult &= "LAN connected" & @LF
    If BitAND($aRet[1], $NETWORK_ALIVE_WAN) Then $iResult &= "WAN connected" & @LF
    If BitAND($aRet[1], $NETWORK_ALIVE_AOL) Then $iResult &= "AOL connected" & @LF
    
    Return $iResult
EndFunc

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Thanks Rasim

Looks good for a start....

I did some investigating and found similar code using "WinInet.dll" instead of "sensapi.dll" do you know if there is any advantages/disadvantages to using one or the other?

Here is some code I cobbled together using "WinInet.dll" after I saw your example and went searching for other bits of code like it.

Global $connType = 1 ; 0 = Permanent (LAN/WIFI), 1 = Non Permanent (Dialup)

While 1
    $state = IsConnected()

    If $state = 1 Then
        If Not Ping("www.google.com", 250) Then
            TrayTip("Internet Connection", "Disconnected, Check Modem For Connection", 2, 2)
        Else
            TrayTip("Internet Connection", "Connected", 2, 2)
            ExitLoop ; Connected to interent so exit loop
        EndIf
    Else
        Select
            Case $connType = 0 ; permenant
                TrayTip("Internet Connection", "Disconnected, Check if the Cable Is unplugged or your WIFI is off", 2, 2)
            Case $connType = 1 ; Dialup
                TrayTip("Internet Connection", "Disconnected, Please Connect to the internet", 2, 2)
        EndSelect
    EndIf
    Sleep(1000)
WEnd

Func IsConnected()
    $IsConnected = DllCall("WinInet.dll", "int", "InternetGetConnectedState", "int_ptr", 0, "int", 0)
    Return $IsConnected[0]
EndFunc   ;==>IsConnected

Exit

Thanks

John Morrison

Edited by storme

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

storme

The IsConnected() function always return 1 for me.

Edit

Global Const $INTERNET_CONNECTION_MODEM = 0x1
Global Const $INTERNET_CONNECTION_LAN = 0x2
Global Const $INTERNET_CONNECTION_PROXY = 0x4
Global Const $INTERNET_CONNECTION_MODEM_BUSY = 0x8
Global Const $INTERNET_RAS_INSTALLED = 0x10
Global Const $INTERNET_CONNECTION_OFFLINE = 0x20
Global Const $INTERNET_CONNECTION_CONFIGURED = 0x40

Dim $State, $val

$InetStruct = DllStructCreate("int")

$aRet = DllCall("wininet.dll", "int", "InternetGetConnectedState", "ptr", DllStructGetPtr($InetStruct), "int", 0)

ConsoleWrite("!> " & $aRet[0] & @LF)

$val = DllStructGetData($InetStruct, 1)

If BitAND($val, $INTERNET_CONNECTION_MODEM) Then $State &= "Modem connection" & @LF
If BitAND($val, $INTERNET_CONNECTION_LAN) Then $State &= "LAN connection" & @LF
If BitAND($val, $INTERNET_CONNECTION_PROXY) Then $State &= "Proxy connection" & @LF
If BitAND($val, $INTERNET_CONNECTION_MODEM_BUSY) Then $State &= "Modem bussy" & @LF
If BitAND($val, $INTERNET_RAS_INSTALLED) Then $State &= "RAS installed" & @LF
If BitAND($val, $INTERNET_CONNECTION_OFFLINE) Then $State &= "Offline connection" & @LF
If BitAND($val, $INTERNET_CONNECTION_CONFIGURED) Then $State &= "Connection configured"

MsgBox(0, "Connection", $State)
Edited by rasim

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

storme

The IsConnected() function always return 1 for me.

What type of connection do you have? (ethernet, wifi, dialup, ???)

I have a cable modem through a wireless router.

If I turn the modem off I get "Check Modem For Connection" "IsConnected=1"

If I disocnnect the ethernet cable or turn off the router or tuen off the wifi on my laptop I get "Check if the Cable Is unplugged or your WIFI is off" "IsConnected=0"

I'm curious why yours doesn't change??

Some of the values the DLL returns are self explanaitory but others are a little cryptic.

Is there any doco on what they actually mean so they can be used with confidence.

Here are my interpretations. Can you confirm I'm right or wrong.

$INTERNET_CONNECTION_MODEM = 0x1

Connected via dialup

Global Const $INTERNET_CONNECTION_LAN = 0x2

Eternet connection but this probably means WIFI, etc

Global Const $INTERNET_CONNECTION_PROXY = 0x4

OK so if I have an ethernet (LAN) cable pugged in and I have a proxy configured

What do I get? Both?

Global Const $INTERNET_CONNECTION_MODEM_BUSY = 0x8

Where would this occure?

Global Const $INTERNET_RAS_INSTALLED = 0x10

What does this indicate?

Global Const $INTERNET_CONNECTION_OFFLINE = 0x20

I unplugged all the cables and did everything except disble the network conneciton and I couldn't get this one to appear.

What does it mean?

Global Const $INTERNET_CONNECTION_CONFIGURED = 0x40

??? Configured for what ???

It looks like teh DLL could be useful but how usfull depends on the interpreation of the data it presents.

Thanks for the help rasim

John MorrisonEthernetdial updisconnectEthernetturnexplanatorydial upEthernetEthernetaccruedisableconnectiontheusefulinterpretation

Edited by storme

Share this post


Link to post
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
Sign in to follow this  
Followers 0