A voir également:
- VBScript - fonction retournant l'IP du poste
- Ethernet n'a pas de configuration ip valide - Guide
- Fonction si et - Guide
- Acheter colis perdu poste - Guide
- Comment connaître son adresse ip - Guide
- Ip local - Guide
1 réponse
Voilà le code que j'ai pondu, mais c'est pas super ...
Auriez vous un code plus rapide (écriture d'un fichier, lecture de celui - ci, pas super), plus propre ?
function getIp(nomPoste)
dim sh, ligneCmd
Set sh = CreateObject("WScript.Shell")
LigneCmd = "cmd /c ping -n 1 -w 15 " & nomPoste & " > c:\temp\IP.txt"
RcA = sh.run(LigneCmd, 1,True)
Dim ip, contents, filesys, readfile, pos1, pos2
getIp = nomPoste
set filesys = CreateObject("Scripting.FileSystemObject")
set readfile = filesys.OpenTextFile("c:\temp\IP.txt", 1, true)
do while readfile.AtEndOfStream=false
contents = readfile.ReadLine
pos1 = InStr(1, contents,"[", 1) + 1 'le 1e chiffre ...
if pos1 <> 1 then
pos2 = InStr(1, contents, "]",1) - 1 'le 2e chiffre
ip = Mid(contents, pos1, pos2 - pos1 + 1)
getIp = ip
readfile.close
exit function
end if
loop
readfile.close
end function
dim pc
pc = InputBox("Merci de rentrer le nom du poste", "Nom du poste", " ")
msgbox getIp(pc)
Auriez vous un code plus rapide (écriture d'un fichier, lecture de celui - ci, pas super), plus propre ?
function getIp(nomPoste)
dim sh, ligneCmd
Set sh = CreateObject("WScript.Shell")
LigneCmd = "cmd /c ping -n 1 -w 15 " & nomPoste & " > c:\temp\IP.txt"
RcA = sh.run(LigneCmd, 1,True)
Dim ip, contents, filesys, readfile, pos1, pos2
getIp = nomPoste
set filesys = CreateObject("Scripting.FileSystemObject")
set readfile = filesys.OpenTextFile("c:\temp\IP.txt", 1, true)
do while readfile.AtEndOfStream=false
contents = readfile.ReadLine
pos1 = InStr(1, contents,"[", 1) + 1 'le 1e chiffre ...
if pos1 <> 1 then
pos2 = InStr(1, contents, "]",1) - 1 'le 2e chiffre
ip = Mid(contents, pos1, pos2 - pos1 + 1)
getIp = ip
readfile.close
exit function
end if
loop
readfile.close
end function
dim pc
pc = InputBox("Merci de rentrer le nom du poste", "Nom du poste", " ")
msgbox getIp(pc)