[vbs] adresse ip publique

Description

C'est un Vbscript pour afficher l'adresse ip publique et de l'enregistrer dans un fichier texte avec la date et l'heure.

Source / Exemple :


Option Explicit
Dim Boucle,strComputer,MsgTitre,objPing,objStatus
Boucle = True
While Boucle = True
strComputer = "smtp.gmail.com"
MsgTitre = "TEST DE CONNEXION INTERNET ET SMTP DE GMAIL © Hackoo © 2012"
Set objPing = GetObject("winmgmts:{impersonationLevel=impersonate}!\\").ExecQuery("select * from Win32_PingStatus where address = '" & strComputer & "'")
For Each objStatus in objPing
If objStatus.Statuscode = 0 Then
msgbox "TEST SMTP DE GMAIL EST OK . VOUS ETES CONNECTE A INTERNET ET LE SMTP DE GMAIL EST DISPONIBLE ! ",64,MsgTitre
Boucle = False
Call Ip_Publique
wscript.quit
else
msgbox "TEST SMTP DE GMAIL EST NO OK . VOUS N'ETES PAS CONNECTE A INTERNET ET LE SMTP DE GMAIL N'EST PLUS DISPONIBLE EN CE MOMENT !",16,MsgTitre
End If
Call ReNewLocalIP
Next
wscript.sleep 60000
Wend

Sub Ip_Publique
Dim Titre,URL,ie,objFSO,Data,OutPut,objRegex,Match,Matches
Titre = "Adresse Ip Publique © Hackoo © 2012"
URL = "http://monip.net"
Set ie = CreateObject("InternetExplorer.Application")
Set objFSO = CreateObject("Scripting.FileSystemObject") 
ie.Navigate (URL) 
ie.Visible=false
DO WHILE ie.busy
wscript.sleep 100
LOOP
Data = ie.document.documentElement.innertext 
Set OutPut = objfso.OpenTextFile("monip.txt",8,True)
ie.Quit 
Set ie = Nothing
Set objRegex = new RegExp
objRegex.Pattern = "\b([0-9]{1,3}\.){3}[0-9]{1,3}\b"
objRegex.Global = False
objRegex.IgnoreCase = True
Set Matches = objRegex.Execute(Data)
For Each Match in Matches   
    MsgBox "Mon IP Publique est : " & vbCr & Match.Value ,64,Titre
    OutPut.WriteLine string(40,"-") & vbcr &"  Nous sommes le "& Now & vbcr & string(40,"-") & vbcr & "  Mon IP Publique est : "& Match.Value & vbcr & string(40,"*")
Next
Call OpenLog("monip.txt")
End Sub

Sub OpenLog(File)
Dim ws
Set ws = CreateObject("wscript.shell")
ws.run "Notepad " & File,1,True
Set ws = Nothing
End Sub

Sub ReNewLocalIP
Dim Ws,command,StrCommand,Resultat
Set Ws = CreateObject("WScript.Shell")
command = "ipconfig /release & ipconfig /flushdns & ipconfig /renew"
StrCommand = "cmd /k "& command &""
Resultat = ws.Run(StrCommand,1,True)
End Sub

Codes Sources

A voir également

Vous n'êtes pas encore membre ?

inscrivez-vous, c'est gratuit et ça prend moins d'une minute !

Les membres obtiennent plus de réponses que les utilisateurs anonymes.

Le fait d'être membre vous permet d'avoir un suivi détaillé de vos demandes et codes sources.

Le fait d'être membre vous permet d'avoir des options supplémentaires.