Jump to content

Recommended Posts

Posted

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

Posted

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)

Posted

  PerryRaptor said:

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.

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
  • Recently Browsing   0 members

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