Jump to content

Check RAS connection


Buffo
 Share

Recommended Posts

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

Link to comment
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

Link to comment
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]

Link to comment
Share on other sites

@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

Link to comment
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

Link to comment
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]

Link to comment
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

Link to comment
Share on other sites

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]

Link to comment
Share on other sites

  • 4 months later...

@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.

Link to comment
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.

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...