Jump to content

Windows VPN


LightsOn
 Share

Recommended Posts

Hi All,

Been using Auto-it for some time now for small little things - mainly in an HA environment to aid in basic automated tasks.  Thank you for the great forum and code etc.

I have a new challenge however that I am stumped with - I researched all yesterday and could not find a solution - hope the community can help.

I want to receive a notification of a VPN connection.  The VPN is on a standard windows 7 machine.  it can only revive one connection at a time.  I am not fussed about knowing who is connected just that there is a connection or not.  Rasdial in cmd works on the host indicating a connection to the client but the client does not see a connection from the host if the same resdial cmd is posted client side.  

I think I could also check if ports are in use / active or not - but not sure how to do this.

I tired using window info to see if the network icon that shows either a connection or not had a change in information shown but it does not.

I want to do the monitoring on the host not on the clients.

I was hoping that using one of the above I could crudely set a task schedule to run and check every 1 minute or similar against either rasdial result, or window info, or port data, and as such do something on a result. but so far no joy in finding a solution that works.

any ideas? Thank you in advance.

Link to comment
Share on other sites

  • Moderators

Could you not check the ip adress on the client, which should change based on the network to which it is connected? Look at the @IPAddress1 macro in the help file.

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

Hi @JLogan3o13

Thanks for the reply.  IP wont ping or show over a vpn sadly.  I have made progress:

Run(@ComSpec & " Cmd /K " & 'netstat -np TCP | find "1723" > C:\path_to\netstat.txt', "", @SW_HIDE)

This creates a .txt with output.

it is populated if a connection and not if no connection.

I am working on using _findinfile to identify if a word is present in the file - this is where i am stuck as cant find simple example code.

i can then do a simple if present do this if not do that set up. and then run the entire thing on a scheduled.

Link to comment
Share on other sites

  • Moderators

Hi @JLogan3o13

Thanks for the reply.  IP wont ping or show over a vpn sadly.

 

Sorry, I must have misunderstood your first post. I thought you were running this from the client that is connecting to the VPN (which should show the IP). Am I to understand you're running it remotely? 

I typically use FileReadToArray, then parse through the array, to find content. Something like this:

#include <File.au3>

Local $aPCs = FileReadToArray(@ScriptDir & "\PCs.txt")

For $machine In $aPCs
    If StringInStr($machine, "13267") Then ConsoleWrite("Found machine " & $machine & @CRLF)
Next

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

Hi @JLogan3o13

Many thanks.

I am running this on the server (Host) and detecting client connections (people connecting to the server)

I am not sure who I would implement your suggestion - I will do more reading.  I know if I could get the _findinfile to work I would be up and running but cant get a simple example to work yet.

Link to comment
Share on other sites

Hi,

A little update:

$ifconected = FileExists("C:VPN_Check\Conection.txt")

Run(@ComSpec & " Cmd /K " & 'netstat -np TCP | find "1723" > C:VPN_Check\netstat.txt', "", @SW_Hide)
sleep(2000);wait for file to be created
if FileGetSize("netstat.txt") < FileGetSize("Example.txt") Then ;if no conection is found
call("disconected")   
Else
call("Conected")    
EndIf

Func disconected()
If $ifconected Then
FileDelete("C:VPN_Check\Conection.txt")
run("C:VPN_Check\Emails\SendEmail_VPN_Disconected.exe");deleted and send email disconecting
FileDelete("C:VPN_Check\netstat.txt")
Else
FileDelete("C:VPN_Check\netstat.txt")
EndIf
EndFunc

Func Conected()
If Not $ifconected Then
   Run("VPN_Check\Emails\SendEmail_VPN_Conected.exe")
   FileOpen(@ScriptDir & "\Conection.txt", 1)
   FileDelete("C:VPN_Check\netstat.txt")
Else
   FileDelete("C:VPN_Check\netstat.txt")
EndIf
EndFunc

This is clunky to say the least but works if manually run.  in simple terms it creates a file that is either populated with data or not dependant on if a VPN is or is not connected.  Then if connected but no flag stating connected then a flag is created.  if no connection is seen and connection flag set it deletes connection flag and sends email. i can then run this via a task schedule every minute

Problem is that when running from task scheduler I get totally different results???? The connection flag is constantly created? so what changes between running this from task scheduler and manually that changes the outcome of the script?

Link to comment
Share on other sites

Update:

It appears from a search that if running from Task Scheduler then full paths are required so have changed:

if FileGetSize("netstat.txt") < FileGetSize("Example.txt") Then ;if no connection is found

to

if FileGetSize("C:VPN_Check\netstat.txt") < FileGetSize("C:VPN_Check\Example.txt") Then ;if no connection is found

So far seem to have fixed things - just checking now.

Link to comment
Share on other sites

Great stuff - confirmed.  full paths added solves the issue.

a crude solution but one that works.

if I could manage a ping to computer-name of some sort I could confirm "who" has actuality connected also - but not a concern for now.  

Hope this is of use to some one.

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