1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
| Dim OWS, objIE, strIETitle, objShell, i, DelaiVPN, btn
' define objects
Set OWS = CreateObject("Wscript.Shell")
Set objShell = CreateObject("WScript.Shell")
i=0
' les constantes
const URL = "http://www.showmyip.com/xml/" 'IP externe
const IpHome = "x.x.x.x" 'IP VPN
const NomVPN = "Connexion VPN"
const Login= "login" 'login AD
const Password= "password" 'pw AD
DelaiVPN= 50 'attente de réponse du serveur VPN (en secondes)
' on determine l'adresse IP
monip(URL)
'connexion ou déconnexion au vpn
if monip(URL) <> IpHome Then
' On lance la connexion VPN
OWS.Run "%comspec% /c rasdial """ & NomVPN & """ " & Login &" " & Password, 0
' cancel arrêt de la tâche planifiée (pour la session en cours).
else
OWS.Run "%comspec% /c schtasks /change /disable /TN ""connexionvpnauto""", 0
WScript.Quit
end if
Do while StrComp(myip,IpHome,1)=-1
i=i+1
Wscript.sleep 1000
if i=DelaiVPN then
'msgbox "VPN inaccessible. Vérifiez les paramètres de connexion au VPN ou les capacités de la connexion."
WScript.Quit
end if
'on vérifie à nouveau l'ip
monip(URL)
loop
OWS.Popup "vous êtes bien connecté à " & NomVPN, 10, "attention", 0 + 4096
function monip(URL)
set xmldoc = CreateObject("Microsoft.XMLDOM")
xmlDoc.validateOnParse = True
xmldoc.async=false
xmldoc.load(URL)
Select Case xmlDoc.parseError.errorCode
Case 0 ' le document xml est valide
for each x in xmldoc.documentElement.childNodes
if x.NodeName = "ip" then
myip = x.text
end if
next
Case Else 'le document xml n'est pas valide (adresse non accessible, vpn en cours de connexion ou pas d'accès web.)
Wscript.Sleep 5000
End Select
end function |
Partager