Jump to content

Match ip to hostname


spanga
 Share

Recommended Posts

Matching IP-adresses could be done by using Windows Ping command with the -a flag. But is there a better/faster way? I need to match 500 IP-adresses in my script so I guess the "Ping -a" method would be kinda slow. Anyone know of a better way to do this?

Got this now:

#include <Constants.au3>
$IP = "64.111.104.70"
$HostNameString = Run(@ComSpec & " /c ping -a -n 1 -w 1 " & $IP, @SystemDir, @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)
$HostName = StringSplit(StringTrimLeft(StdoutRead($HostNameString),25)," ")
$HostName = $HostName[1]

Allthough I'm still interested in a workaround the Run-function, as me nor some AV's dislike programs executing other programs.

Edited by spanga
Link to comment
Share on other sites

also, autoit has its own ping command.. so you don't need to do a run at all.

[u]Helpful tips:[/u]If you want better answers to your questions, take the time to reproduce your issue in a small "stand alone" example script whenever possible. Also, make sure you tell us 1) what you tried, 2) what you expected to happen, and 3) what happened instead.[u]Useful links:[/u]BrettF's update to LxP's "How to AutoIt" pdfValuater's Autoit 1-2-3 Download page for the latest versions of Autoit and SciTE[quote]<glyph> For example - if you came in here asking "how do I use a jackhammer" we might ask "why do you need to use a jackhammer"<glyph> If the answer to the latter question is "to knock my grandmother's head off to let out the evil spirits that gave her cancer", then maybe the problem is actually unrelated to jackhammers[/quote]

Link to comment
Share on other sites

  • 1 month later...

If you have all 500 IP Addresses listed on a single line in a text file you could use FileReadLine(), pass it to the MS_DOS Ping command, and create a new text file with IP Address and the corresponding Hostname on each line.

To decrease the time it takes MS_DOS Ping to return info add the "-n 1" switch to ping destination only once.

I use such a script at work against thousands of workstations...takes about 2 - 3 minutes depending on network bandwidth.

Make sure you add a feature for skipping over workstations that are offline.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...