Go Back   TechArena Community > Technical Support > Computer Help > Windows Server > Windows Server Help
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Sponsored Links



Script to find host names from list of IPs

Windows Server Help


Reply
 
Thread Tools Search this Thread
  #1  
Old 24-03-2008
Azad
 
Posts: n/a
Script to find host names from list of IPs

I am looking for a script which can read a .txt file with a list of IP
addreses and fetch me the hostnames. Ideally the output format should be "IP:
xxx.xxx.xxx.xxx Host Name: ABCXXX". Could someone help me please?
I may not have admin access on some of the boxes, the script I am looking
for should work in these conditions as well. At the moment, I am using very
rudimentary method of writing a batch file with several entries of Ping -a
xxx.xxx.xxx.xxx >> output.txt which I have to massage it to get the desired
result.

Reply With Quote
  #2  
Old 24-03-2008
Pegasus \(MVP\)
 
Posts: n/a
Re: Script to find host names from list of IPs


"Azad" <Azad@discussions.microsoft.com> wrote in message
news:B4E26160-6093-44AD-8A33-62FC6A0D693E@microsoft.com...
>I am looking for a script which can read a .txt file with a list of IP
> addreses and fetch me the hostnames. Ideally the output format should be
> "IP:
> xxx.xxx.xxx.xxx Host Name: ABCXXX". Could someone help me please?
> I may not have admin access on some of the boxes, the script I am looking
> for should work in these conditions as well. At the moment, I am using
> very
> rudimentary method of writing a batch file with several entries of Ping -a
> xxx.xxx.xxx.xxx >> output.txt which I have to massage it to get the
> desired
> result.


You could do this with a simple batch file:
@echo off
for /F %%a in ('type d:\temp\IP.txt') do call :Sub %%a
goto :eof

:Sub
for /F %%b in ('nbtstat -A %1 ^| find "<00>" ^| find /i "unique"') do echo
%IP% Hostname: %%b


Reply With Quote
  #3  
Old 24-03-2008
Azad
 
Posts: n/a
Re: Script to find host names from list of IPs

I get an error:

'Hosname' is not recognized as an internal or external command,
operable program or batch file.
Reply With Quote
  #4  
Old 24-03-2008
Pegasus \(MVP\)
 
Posts: n/a
Re: Script to find host names from list of IPs


"Azad" <Azad@discussions.microsoft.com> wrote in message
news:BF71FE96-4EA3-4D06-93E8-A0422073805C@microsoft.com...
>I get an error:
>
> 'Hosname' is not recognized as an internal or external command,
> operable program or batch file.


Let's have a look at your batch file! Please mark clearly where
your lines start, e.g. like so:
Line1=@echo off
Line2=for /F %%a in ('type d:\temp\IP.txt') do call :Sub %%a
Line3=goto :eof


Reply With Quote
  #5  
Old 25-03-2008
Azad
 
Posts: n/a
Re: Script to find host names from list of IPs

Thank you! That did fetch some results.

3 things that I noticed in the output:
1. IP address column is not seen in the output.
2. The Hostname shows <hostname>-W
3. I had about 150 IPs in the IP.txt file, the output had only 43 hostnames

Reply With Quote
  #6  
Old 25-03-2008
Pegasus \(MVP\)
 
Posts: n/a
Re: Script to find host names from list of IPs


"Azad" <Azad@discussions.microsoft.com> wrote in message
news:D7DAFB00-C317-43B4-90AD-A0976643BA86@microsoft.com...
> Thank you! That did fetch some results.
>
> 3 things that I noticed in the output:
> 1. IP address column is not seen in the output.
> 2. The Hostname shows <hostname>-W
> 3. I had about 150 IPs in the IP.txt file, the output had only 43
> hostnames
>


Sorry, unless you post your version of the code I cannot
assist you.


Reply With Quote
  #7  
Old 25-03-2008
Pegasus \(MVP\)
 
Posts: n/a
Re: Script to find host names from list of IPs


"Azad" <Azad@discussions.microsoft.com> wrote in message
news:D7DAFB00-C317-43B4-90AD-A0976643BA86@microsoft.com...
> Thank you! That did fetch some results.
>
> 3 things that I noticed in the output:
> 1. IP address column is not seen in the output.
> 2. The Hostname shows <hostname>-W
> 3. I had about 150 IPs in the IP.txt file, the output had only 43
> hostnames
>


As a further thought: You should also post the
output you get when executing this command
for an IP address that does NOT generate
the expected output:

nbtstat -A aaa.bbb.ccc.ddd


Reply With Quote
  #8  
Old 26-03-2008
Azad
 
Posts: n/a
Re: Script to find host names from list of IPs

***Code***
@echo off
for /F %%a in ('type D:\test\IP.txt') do call :Sub %%a
goto :eof

:Sub
for /F %%b in ('nbtstat -A %1 ^| find "<00>" ^| find /i "unique"') do echo
%IP% Hostname %%b
***Command that I run***
D:\Test>pinglist >> output.txt
***Output***
Hostname 7996S1-W
Hostname 7920S1-W
***Output of nbtstat -A of missing info***
>nbtstat -A 10.9.160.40


Local Area Connection 4:
Node IpAddress: [172.17.224.83] Scope Id: []

Host not found.

Reply With Quote
  #9  
Old 26-03-2008
Pegasus \(MVP\)
 
Posts: n/a
Re: Script to find host names from list of IPs

I made a mistake in my script. It should read like so:
@echo off
for /F %%a in ('type D:\test\IP.txt') do call :Sub %%a
goto :eof

:Sub
for /F %%b in ('nbtstat -A %1 ^| find "<00>" ^| find /i "unique"') do echo
%1 Hostname %%b

About the command that fails to generate an output:
nbtstat -A 10.9.160.40
I cannot help you there. Either the machine 10.9.160.40
has some firewall restriction or there is something wrong
with its IP configuration. You can test the firewall part by
executing the command nbtstat -A 10.9.160.40 on the
machine itself.


"Azad" <Azad@discussions.microsoft.com> wrote in message
news:8236C1B2-C071-4071-9FD8-1B99D7DFBE3F@microsoft.com...
> ***Code***
> @echo off
> for /F %%a in ('type D:\test\IP.txt') do call :Sub %%a
> goto :eof
>
> :Sub
> for /F %%b in ('nbtstat -A %1 ^| find "<00>" ^| find /i "unique"') do echo
> %IP% Hostname %%b
> ***Command that I run***
> D:\Test>pinglist >> output.txt
> ***Output***
> Hostname 7996S1-W
> Hostname 7920S1-W
> ***Output of nbtstat -A of missing info***
>>nbtstat -A 10.9.160.40

>
> Local Area Connection 4:
> Node IpAddress: [172.17.224.83] Scope Id: []
>
> Host not found.
>



Reply With Quote
Reply

  TechArena Community > Technical Support > Computer Help > Windows Server > Windows Server Help
Tags: , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Script to find host names from list of IPs"
Thread Thread Starter Forum Replies Last Post
list of the stadium names in Pro Evolution Soccer 2012 Upkeerat Video Games 5 06-10-2011 09:29 PM
List the names of sheets in an Excel document ASHER Software Development 3 19-11-2009 06:32 PM
Cannot resolve host names over VPN trm96 Windows Vista Network 4 17-03-2009 08:47 PM
Windows Script Host Error motasim Operating Systems 1 13-12-2008 01:46 PM
Need a script to capture computer names in IP range Rick Neely Windows Server Help 3 21-11-2007 10:17 AM


All times are GMT +5.5. The time now is 10:59 AM.