• 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: Adam Bell <email@hidden>
  • Date: Sun, 12 Feb 2006 17:15:37 -0400

To test the number itself, this might do it:

set IPAdd to "233.240.123.1" -- my sample. Try with invalid numbers too.
set {TID, text item delimiters} to {text item delimiters, "."}
set parts to (text items of IPAdd)
set text item delimiters to TID
set CP to count of parts
if CP > 4 or CP < 4 then
    display dialog "An IP Address must have four elements separated by periods"
else
    repeat with k from 1 to 4
        set aNum to item k of parts as number
        if aNum > 253 or aNum < 1 then
            display dialog ("In your entry: " & parts as string) & ", " & (item k of parts) & " must be a number between 1 and 254"
            exit repeat
        end if
    end repeat
    display dialog ("Your entry: " & parts as string) & " is a valid address"
end if



On 2/12/06, Timothy Bates <email@hidden> wrote:
IPs are of the form

n.n.n.n

where n is a number between 0 and 255

So you want to
1. Split on "."
2. Count what you get: there should be 4 items
3 Check each item is an integer between 0 and 255

This would be a start
set a to "123.123.123"
set oldDelimiters to AppleScript's text item delimiters
set AppleScript's text item delimiters to "."
set x to text items of a
set AppleScript's text item delimiters to oldDelimiters
--return count x
if (count x) ‚ 4 then
    display dialog "I need 4 numbers separated by periods (not " & (count x)
& ").

Your string was: " & a

end if

> 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.
>
> does anyone have an example on how I can validate the IP address?


_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list      (email@hidden
This email sent to
email@hidden



--
Some minds remain open long enough for a truth to both enter and leave without processing.
 _______________________________________________
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

References: 
 >Validate IP Address (From: Tom Jones <email@hidden>)
 >Re: Validate IP Address (From: Timothy Bates <email@hidden>)

  • Prev by Date: 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