From: حب الحسين أجنني on
Good day,

I need a script to read IPs from a text file and provide me with the
hostname for each IP. Can anyone help me in that?

Thanks in advance
From: Pegasus [MVP] on


"?? ?????? ?????" <amnemer(a)gmail.com> said this in news item
news:f311115f-a6a3-4c3b-9ec7-cebe50d84e60(a)p24g2000yqm.googlegroups.com...
> Good day,
>
> I need a script to read IPs from a text file and provide me with the
> hostname for each IP. Can anyone help me in that?
>
> Thanks in advance

What does the text file look like?

From: Corey Thomas on
It's not the most elegant code but will get the job done. Pass it an
IP and it will do a ping -a and return back the resolved machine name
or blank if it can't resolve.
Caveat:. This does NOT verify the machine is online. It is possible
to return the resolved name but not actually ping it.

Function getMachineFromIP(sstrIP)
'Input: sstrIP= IP Address of machine
'Output: String = machine name

getMachineFromIP=""
strMachine = Trim(sstrIP)
Set sobjShell = WScript.CreateObject("WScript.Shell")
Set sobjExecObject = sobjShell.Exec("ping -a " & sstrIP)
Do While Not sobjExecObject.StdOut.AtEndOfStream
strText = sobjExecObject.StdOut.ReadLine()
If Instr(strText, "Pinging") > 0 Then
arrString = Split(strText," ")
getMachineFromIP=arrString(1)
Exit Do
End If
Loop
Set sobjShell = Nothing
End Function



On Jan 20, 12:56 am, حب الحسين أجنني <amne...(a)gmail.com> wrote:
> Good day,
>
> I need a script to read IPs from a text file and provide me with the
> hostname for each IP. Can anyone help me in that?
>
> Thanks in advance

From: mayayana on
One option here:

http://www.jsware.net/jsware/scripts.php5#jshttp

This is a free component. In addition to doing hostname
translation it has functions to use a publicly available
database from MaxMind.com to provide geo-location
data. In other words, from an IP address it can return
both the hostname and the server location in terms
of city/state/country.
The download comes with a sample script for translating
raw server log entries. (See IPInfo.vbs) It just requires
slight editing to match the formatting/syntax of your
particular text file. If memory serves, I think I wrote it
to deal with Apache logs that put each GET on a line
starting like so: 100.100.100.100 --

You may also be able to do hostname resolution with
built-in Windows functionality, but I'm not sure about
that. (If so, someone should be along shortly to explain
it. :)


--
--
?? ?????? ????? <amnemer(a)gmail.com> wrote in message
news:f311115f-a6a3-4c3b-9ec7-cebe50d84e60(a)p24g2000yqm.googlegroups.com...
> Good day,
>
> I need a script to read IPs from a text file and provide me with the
> hostname for each IP. Can anyone help me in that?
>
> Thanks in advance


From: James Whitlow on
"?? ?????? ?????" <amnemer(a)gmail.com> wrote in message
news:f311115f-a6a3-4c3b-9ec7-cebe50d84e60(a)p24g2000yqm.googlegroups.com...
> Good day,
>
> I need a script to read IPs from a text file and provide me with the
> hostname for each IP. Can anyone help me in that

Assuming a filename of 'IP Addresses.txt' in the same directory as the
script, the below code should work for you.

'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Dim oFSO, oWMI, oInpFile, oOutFile, oPing, oItem
Dim sInpFile, sOutFile, sIP, sHost

sInpFile = "IP Addresses.txt"
sOutFile = "Host Names.txt"

Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oWMI = GetObject("WinMgmts:")

If Not oFSO.FileExists(sInpFile) Then WScript.Quit

Set oInpFile = oFSO.OpenTextFile(sInpFile, 1)
Set oOutFile = oFSO.OpenTextFile(sOutFile, 2, True)

Do Until oInpFile.AtEndOfStream
sIP = oInpFile.ReadLine
If UBound(Split(sIP, ".")) = 3 Then
oOutFile.Write sIP & ","
Set oPing = oWMI.ExecQuery _
("SELECT * From Win32_PingStatus WHERE Address='" _
& sIP & "' AND ResolveAddressNames=TRUE")
For Each oItem in oPing
oOutFile.WriteLine oItem.ProtocolAddressResolved
Next
End If
Loop

MsgBox "Done"
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~