• 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: Mon, 13 Feb 2006 01:21:54 -0400

Apologies for "there own addresses...", understand "their"

On 2/13/06, Adam Bell <email@hidden > wrote:
Nice coverage, Kai. It won't catch a pre-assigned IP Address (on a LAN presumably) if that machine is off or asleep, however, so if an address is chosen ( 192.168.1.22, say) and that machine is then started, it will be rejected upstream without necessarily knowing who the "sinner" might be.

The real problem for all these solutions, of course (interesting though they are) is that we haven't a clue what Tom Jones had in mind. If he is an admin of a LAN and wants to select IP Addresses for new entries so he can, for example, easily set up port forwarding on a dumb router to that machine, then all this might work - the user might even be given a choice in a range and the choice can be rejected if it exists or doesn't meet any other criteria set (like the first two or three elements). If individuals are going to set there own IP addresses, not a chance in hell.

On a LAN, private (masqueraded) addresses usually fall in these ranges (they are "private" because routers ignore them - don't pass them on):
10.0.0.0 - 10.255.255.255 -- often used by cable companies for their own routers; a huge set
172.16.0.0 - 172.31.255.255 -- smaller set used by large corporations with many sites.
192.168.0.0 - 192.168.255.255 -- the usual set for small LANS, 64K addresses
0.0.0.0 - default route
127.x.x.x - loopback address -- i.e. yourself -  zeros at the end refer to the network
x.x.255.255 is a broadcast address to all machines on x.x. -- which is why 255 is not normally a client address. In addition, routers often take "1" on a subnet, so 1 is not valid for clients either.


On 2/12/06, kai < email@hidden> wrote:

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



--
Some minds remain open long enough for a truth to both enter and leave without processing.



--
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: kai <email@hidden>)
 >Re: Validate IP Address (From: Adam Bell <email@hidden>)

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