Sign in to follow this  
Followers 0
Buffo

Check RAS connection

15 posts in this topic

Hi

Is it possible to get the state of a ras connection without connect to the internet if no connection is available?

With checking the ping time every time the internet connection will be accomplished.

Regards,

Buffo

Share this post


Link to post
Share on other sites



You could capture the output of an IPCONFIG /ALL command with StdoutRead and see if your RAS connection's name shows up in that output.


[font="Fixedsys"][list][*]All of my AutoIt Example Scripts[*]http://saneasylum.com[/list][/font]

Share this post


Link to post
Share on other sites

Great idea :whistle:

I don't have a RAS connection here. Can any one give me examples of the connected/disconnected output?

Thx in advance!

Regards,

Buffo

Share this post


Link to post
Share on other sites

@Zedna: Thx for your reply but I don't want additional files for my project :whistle:

I think analyzing the StdOutRead output will be the best for me.

I only need output examples because I have no dial-up connection...

Regards,

Buffo

Share this post


Link to post
Share on other sites

Ohh, even better, there seems to be a registry key:

msgbox(0,"Connected via RAS?",OnRas())

Func OnRas()
    $ras = RegRead("HKLM\System\CurrentControlSet\Services\RemoteAccess","Remote Connection")
    if $ras = "01000000" then
        return True
    else
        return False
    endif 
EndFunc


[font="Fixedsys"][list][*]All of my AutoIt Example Scripts[*]http://saneasylum.com[/list][/font]

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

@lod3n

That value is not available with a vpn connection .. in another thread of mine in which you've replied Run a Function in the Background, Function disables GUI

I use the following but have a problem with a loop

Func SetConnectionCheck ()
    $IP1 = @IPAddress1
    $IP2 = @IPAddress2
    $IP3 = @IPAddress3
    $IP4 = @IPAddress4
        If $IP2 = "0.0.0.0" Then
                 $IPUSED = @IPAddress1
        ElseIf $IP3 = "0.0.0.0" Then
                 $IPUSED = @IPAddress2
        ElseIf $IP4 = "0.0.0.0" Then
                 $IPUSED = @IPAddress3
        Else 
                 $IPUSED = @IPAddress4
        EndIf
    TCPStartup ( )
    $CHECKINGUI = "True"
    While 1
                    Sleep ( 500 )
        $var = Ping($IPUSED, 500)                   
        If $var = 0 Then
                 TraySetIcon ("off.ico")
                 TraySetToolTip ("Connection is lost")
                 TrayTip ("Error", "Connection is lost", 5)
                 TrayItemSetState ($TryDisc, 128)
                 $CHECKINGUI = ""
                 MsgBox(16,"Connection Error", "Connection is lost", 5) 
                 Exitloop
        EndIf
    WEnd
EndFunc
Edited by Emiel Wieldraaijer

Best regards,Emiel Wieldraaijer

Share this post


Link to post
Share on other sites

@Emiel Wieldraaijer: Unfortunately I have no RAS connection to test your script. But it is an interesting attempt. I don't know your pob with the loop but the first impression to me is that a While...WEnd should not be used in a function. The loop should be in the main script and call the function. Your script will last in the loop if no connection is available. And I would delete the MsgBox(). It must be annoying :whistle:

Something like this...

HotKeySet("^q", "Quit")

While 1
     If Not CheckConnection() Then
         TraySetIcon ("off.ico")
         TraySetToolTip ("Connection is lost")
         TrayTip ("Error", "Connection is lost", 5)
         TrayItemSetState ($TryDisc, 128)
         MsgBox(16,"Connection Error", "Connection is lost", 5)    
     EndIf
     Sleep(1000)
WEnd

Func Quit()
    Exit
EndFunc

Func CheckConnection()
    $IP1 = @IPAddress1
    $IP2 = @IPAddress2
    $IP3 = @IPAddress3
    $IP4 = @IPAddress4
    If $IP2 = "0.0.0.0" Then
       $IPUSED = @IPAddress1
    ElseIf $IP3 = "0.0.0.0" Then
       $IPUSED = @IPAddress2
    ElseIf $IP4 = "0.0.0.0" Then
       $IPUSED = @IPAddress3
    Else
       $IPUSED = @IPAddress4
        EndIf
    TCPStartup ( )
    $var = Ping($IPUSED, 500)                    
    TCPShutdown()
     Return $var  
EndFunc

@lod3n: I tried your solution and I am wait for a reply of my test user. You wrote you are not sure if it works, if any one knows more I would be happy to know, too ;)

Is it not possible for someone to post the ipconfig /all ouput in connected and disconnected state? I think this will be the most secure way...

Regards,

Buffo

Share this post


Link to post
Share on other sites

Okay:

#include <Constants.au3>

$ipcfg = readIpConfig()

if stringinstr($ipcfg,"VPN") or stringinstr($ipcfg,"PPP") Then
    msgbox(0,"","Connected Remotely")
Else
    msgbox(0,"","Not Connected Remotely")
EndIf


func readIpConfig()
    $foo = Run("ipconfig /all", @SystemDir, @SW_HIDE, $STDOUT_CHILD)
    $output = ""
    While 1
        $output &= StdoutRead($foo)
        If @error Then ExitLoop
    Wend
    consolewrite($ipcfg)
    return $output
EndFunc

Hopefully, "VPN" or "PPP" appear in the ipconfig output if they are remote. You'll have to test this.


[font="Fixedsys"][list][*]All of my AutoIt Example Scripts[*]http://saneasylum.com[/list][/font]

Share this post


Link to post
Share on other sites

@lod3n: Thx!

Short summary: Every time an internet connection is accomplished "PPP" will be anywhere displayed. Every time an VPN connection is accomplished "VPN" will be in the output.

It could be that the name of the ras connection would be displayed or something else, I don't know. That why I ask ;)

I will test it and give feedback :whistle:

Regards,

Buffo

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

I am connected to the Internet, but not by dialup, and "PPP" is not displayed. But, I'm still not sure that will work. But perhaps you could use the registry function to check dialup, and the ipconfig function to check VPN. That ought to work.

Edited by lod3n

[font="Fixedsys"][list][*]All of my AutoIt Example Scripts[*]http://saneasylum.com[/list][/font]

Share this post


Link to post
Share on other sites

I use the rasdial command at the command line to see if my VPN connection is currently connected. Just type that in with no arguments.

Share this post


Link to post
Share on other sites

#13 ·  Posted (edited)

@lod3n: Thx!

Short summary: Every time an internet connection is accomplished "PPP" will be anywhere displayed. Every time an VPN connection is accomplished "VPN" will be in the output.

It could be that the name of the ras connection would be displayed or something else, I don't know. That why I ask :D

I will test it and give feedback :P

Regards,

Buffo

Don't know if that helps but I googled a bit and came across some support forum (-=* HERE *=-) and found this: (and btw yes it mentions both VPN and RAS! :whistle:)

My client can VPN into the RRAS box and receives DHCP/DNS/WINS

information properly from the appropriate server on the LAN. Here's the

output of "ipconfig/all" from the client while connected:

----------------

Windows 2000 IP Configuration

Host Name . . . . . . . . . . . . : feline

Primary DNS Suffix . . . . . . . :

Node Type . . . . . . . . . . . . : Hybrid

IP Routing Enabled. . . . . . . . : No

WINS Proxy Enabled. . . . . . . . : No

DNS Suffix Search List. . . . . . : example.com

Ethernet adapter Local Area Connection:

Connection-specific DNS Suffix . :

Description . . . . . . . . . . . : NETGEAR FA310TX Fast Ethernet

Adapter (NGRPCI)

Physical Address. . . . . . . . . : 00-A0-CC-5D-A4-D6

DHCP Enabled. . . . . . . . . . . : No

IP Address. . . . . . . . . . . . : 192.168.0.2

Subnet Mask . . . . . . . . . . . : 255.255.255.0

Default Gateway . . . . . . . . . : 192.168.0.1

DNS Servers . . . . . . . . . . . : 192.168.0.1

PPP adapter VPN via Uranus:

Connection-specific DNS Suffix . : example.com

Description . . . . . . . . . . . : WAN (PPP/SLIP) Interface

Physical Address. . . . . . . . . : 00-53-45-00-00-00

DHCP Enabled. . . . . . . . . . . : No

IP Address. . . . . . . . . . . . : 192.168.2.145

Subnet Mask . . . . . . . . . . . : 255.255.255.255

Default Gateway . . . . . . . . . :

DNS Servers . . . . . . . . . . . : 192.168.2.2

192.168.2.2

192.168.3.2

Primary WINS Server . . . . . . . : 192.168.2.2

Secondary WINS Server . . . . . . : 192.168.3.2

Edited by SadBunny

Roses are FF0000, violets are 0000FF... All my base are belong to you.

Share this post


Link to post
Share on other sites

Don't know if that helps but I googled a bit and came across some support forum (-=* HERE *=-) and found this: (and btw yes it mentions both VPN and RAS! :P)

And how the hell did I miss the fact that this is a 6 months old thread! ARGH :whistle:


Roses are FF0000, violets are 0000FF... All my base are belong to you.

Share this post


Link to post
Share on other sites

It's really a couple of months ago I asked the question and I don't need any answers any more but I want to thank you although for your help :whistle:

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