|
| |||||||||
| Tags: host, ips, script |
![]() |
| | Thread Tools | Search this Thread |
|
#1
| |||
| |||
| 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. |
|
#2
| |||
| |||
| 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 |
|
#3
| |||
| |||
| 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. |
|
#4
| |||
| |||
| 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 |
|
#5
| |||
| |||
| 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 |
|
#6
| |||
| |||
| 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. |
|
#7
| |||
| |||
| 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 |
|
#8
| |||
| |||
| 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. |
|
#9
| |||
| |||
| 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. > |
![]() |
|
| Thread Tools | Search this Thread |
| |
Similar Threads for: "Script to find host names from list of IPs" | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Export user names as a list? | . | Active Directory | 1 | 09-03-2010 04:48 AM |
| Server DNS host names keep deleting, what could be the reason? | Gonzo | Active Directory | 4 | 27-08-2009 03:26 PM |
| Cannot resolve host names over VPN | trm96 | Windows Vista Network | 4 | 17-03-2009 09:47 PM |
| Problem pinging IP and host names - Server 2003 DNS | Bob | Windows Server Help | 6 | 22-10-2008 09:15 PM |
| Need a script to capture computer names in IP range | Rick Neely | Windows Server Help | 3 | 21-11-2007 10:17 AM |