Jump to content
Sign in to follow this  
aaronj

Get IP address from FQDN

Recommended Posts

aaronj

I'm new to AutoIt scripting and need a little assistance. I need to ping a FQDN (www.autoit.com) and then save the IP address as a variable for other commands.

I'm sure there is an easy way to do this but I haven't found it yet. I'm just using the _RunDOS for my ping command.

Any help would be appreciated.

Thanks,

Aaron

Share this post


Link to post
Share on other sites
PerryRaptor

Pipe the DOS ping command to a temporary file. second, read it into a varible. third, strip out all the data you don't want, forth save the result as a varible.

Check this out...

----------------------------------------------------------------------------------

Local $strcomputer,$ip

$strcomputer = @computername

$strcomputer = InputBox("Display I.P. Address", "Enter the ComputerName for a remote PC, a web address, or press the {OK} button to show My_IP.", $strComputer, "")

; Ready to run the Ping, save the returned information to \Documents and Settings\[currentUser]\Find_IP.txt

RunWait(@ComSpec & " /C Ping -a -n 1 " & $strcomputer & "> Find_IP.txt",@MyDocumentsDir, @SW_HIDE)

$ip = FileRead(@MyDocumentsDir & "\Find_IP.txt", FileGetSize(@MyDocumentsDir & "\Find_IP.txt"))

FileDelete(@MyDocumentsDir & "\Find_IP.txt")

; Now lets look at all of the returned data...

MsgBox(0,"Returned Ping String [data]", "" & $ip)

; Lets search for the first occurance of "[.............]" and get rid of everything else

$ip = StringTrimLeft($ip, StringInStr($ip, "["))

$ip = StringLeft($ip, StringInStr($ip, "]")-1)

; Now, We will only return the I.P. address

MsgBox(0,"" & $strcomputer & " IP:", "" & $ip)

Share this post


Link to post
Share on other sites
aaronj

Pipe the DOS ping command to a temporary file. second, read it into a varible. third, strip out all the data you don't want, forth save the result as a varible.

<{POST_SNAPBACK}>

You are awesome! Thanks PerryRaptor

Your code works perfectly. I thought I was going to have to do something like that but had no clue how to do it.

I'll post my script/program to the forum when I'm done. It's basically a diagnostic tool that checks Windows PCs for proper name resolution, NetBIOS state, and RPC connectivity.

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.