• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Validate IP Address
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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
  • Follow-Ups:
    • Re: Validate IP Address
      • From: Adam Bell <email@hidden>
References: 
 >Validate IP Address (From: Tom Jones <email@hidden>)

  • Prev by Date: Re: Replace files
  • Next by Date: Re: Validate IP Address
  • Previous by thread: Re: Validate IP Address
  • Next by thread: Re: Validate IP Address
  • Index(es):
    • Date
    • Thread