Get IP address for a remote computer based on its hostname
Hi
try:
'----------------------------------------
Sub test()
Dim v As Variant
Dim Filename As String, f As String
Dim ip As String
Filename = "E:\iptemp"
'Create command file
f = CreateCommandFile(Filename, "www.yahoo.com")
'run the command in silent mode
Shell f, vbHide
'get info from output file
v = GetIpInfo(Filename & ".txt")
MsgBox v
'add code here to delete files
End Sub
'Creates a .bat file containing ping. Output into file FileName & ".txt"
Function CreateCommandFile(Filename As String, ip As String)
Dim n As Long, File As String, s As String
File = Filename & ".bat"
s = "ping " & ip & " " & Filename & ".txt"
n = FreeFile()
Open File For Output Access Write As #n
Print #n, s
Close #n
CreateCommandFile = File
End Function
'Get ip info
' need to add code in case of no reply during the ping
Function GetIpInfo(Filename As String)
Dim n As Long, s As String
n = FreeFile()
Open Filename For Input Access Read As #n
Line Input #n, s
Line Input #n, s
Line Input #n, s 'data on third row
Close #n
'extract info within the 2 brackets [ ] of text file
n = Strings.InStr(s, "[")
s = Strings.Right(s, Len(s) - n)
n = Strings.InStr(s, "]")
s = Strings.Left(s, n - 1)
GetIpInfo = s
End Function
'---------------------------------------------------------
--
Regards,
Sébastien
<http://www.ondemandanalysis.com
"stabilo" wrote:
I'd like to get, with VBA, the IP address(es) if a computer based on its
hostname :
eg. Cell "a1" = PCXXX
Cell "a2" = XX.XX.XX.XX
I have seen some example that put the result of a ping into a text file,
then pars this text file and put in cells the ip address into a cell.
Is there another way ? I'm using Excel 2003
|