Results 1 to 9 of 9

Thread: Script to find host names from list of IPs

  1. #1
    Azad Guest

    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. #2
    Pegasus \(MVP\) Guest

    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. #3
    Azad Guest

    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. #4
    Pegasus \(MVP\) Guest

    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. #5
    Azad Guest

    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. #6
    Pegasus \(MVP\) Guest

    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. #7
    Pegasus \(MVP\) Guest

    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. #8
    Azad Guest

    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. #9
    Pegasus \(MVP\) Guest

    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.
    >




Similar Threads

  1. Replies: 5
    Last Post: 06-10-2011, 09:29 PM
  2. List the names of sheets in an Excel document
    By ASHER in forum Software Development
    Replies: 3
    Last Post: 19-11-2009, 06:32 PM
  3. Cannot resolve host names over VPN
    By trm96 in forum Windows Vista Network
    Replies: 4
    Last Post: 17-03-2009, 08:47 PM
  4. Windows Script Host Error
    By motasim in forum Operating Systems
    Replies: 1
    Last Post: 13-12-2008, 01:46 PM
  5. Need a script to capture computer names in IP range
    By Rick Neely in forum Windows Server Help
    Replies: 3
    Last Post: 21-11-2007, 10:17 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,570,955.67747 seconds with 17 queries