Sign in to follow this  
Followers 0
spanga

Match ip to hostname

8 posts in this topic

#1 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites



For hostname to IP you can use TCPNameToIp from the beta (http://www.autoitscript.com/autoit3/files/beta/autoit/)

But IP to Hostname? I will try to write a script for it but its not so easy... So i don't know if i can get it done.


Sorry for my English, I'm Dutch... =DMedia UDFINet Adv UDF

Share this post


Link to post
Share on other sites

DOS has a nice DNS<->IP command, commonly known as 'nslookup' B)

Just do a string manipulation with that, and viola


Writing AutoIt scripts since
_DateAdd("d", -2, _NowCalcDate())

Share this post


Link to post
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]

Share this post


Link to post
Share on other sites

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

won't return the hostname tho.


SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

I put this in Scripts & Scraps...

I.P. <> HostName

Edited by PerryRaptor

Share this post


Link to post
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
Sign in to follow this  
Followers 0