Re: Validate IP Address
Re: Validate IP Address
- Subject: Re: Validate IP Address
- From: kai <email@hidden>
- Date: Mon, 13 Feb 2006 01:51:19 +0000
On 12 Feb 2006, at 20:35, Tom Jones wrote:
I'm working on a small apple script which will set a systems IP
address. I have it pop up a dialog to enter the address and that
works fine. But What I'm need of is a way to validate the IP
address is in the correct format.
While by no means addressing all the issues involved, Tom, this
attempts to trap a few of the more common errors. It also gives the
user the chance to modify the address when an error occurs.
------------------
to get_IP_address(dlogMsg, currAnswer)
set currAnswer to text returned of (display dialog dlogMsg default
answer currAnswer)
set tid to text item delimiters
set text item delimiters to "."
set byteList to currAnswer's text items
set text item delimiters to tid
try
if (count byteList) is not 4 then ¬
error "The address should contain 4 integers separated by periods."
repeat with byteNum from 1 to 4
set currByte to byteList's item byteNum
if (count currByte) is 0 then error "Byte number " & ¬
byteNum & " contains no value."
tell currByte as integer
if it as string is not currByte then error "\"" & ¬
currByte & "\" contains a non-numeric character."
if it < 0 or it > 255 then error "\"" & ¬
currByte & "\" is not between 0 and 255."
end tell
end repeat
do shell script "ping -c 1 -t 1 " & currAnswer
currAnswer
on error errorMsg
if errorMsg starts with "PING" then ¬
set errorMsg to "Could not connect to: " & currAnswer & "."
get_IP_address(errorMsg & " Please try again:", currAnswer)
end try
end get_IP_address
set IP_address to get_IP_address("Please enter the required IP
address:", "")
------------------
---
kai
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden