• 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: Sorting IP addresses
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Sorting IP addresses


  • Subject: Re: Sorting IP addresses
  • From: Steve Mills <email@hidden>
  • Date: Wed, 17 Dec 2003 11:26:00 -0600

On Dec 17, 2003, at 8:37 AM, Marconi wrote:

Given a list of IP addresses, I need to sort them in proper (ascending) order. That is, I need a routine which knows that 205.192.32.45 comes AFTER 65.163.82.130 and so forth.

I think the key would be setting text item delimiters to a period and then sorting on each quad.

Right on the delimiter part. But I think a better way to sort them would be as one number. Since each part of an address can be in the range of 0-255, that means each part can fit into a byte. Put the 4 bytes together and you have a long. Sorting a single long should be much easier than sorting 4 subparts.

So if you turn each IP into a list of 4 strings, you can turn each list into a number like this bit of AppleScript/C mixture:

((item 1 of p) as number << 24) + ((item 2 of p) as number << 16) + ((item 3 of p) as number << 8) + (item 4 of p) as number

The hard part is doing the bit shifting in AS. Is that possible? I'm tired, I just got up, and I'm on vacation, so my brain isn't up to full speed.

Steve Mills
Drummer, Mac Geek
http://sjmills5.home.mchsi.com/
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.

  • Follow-Ups:
    • Re: Sorting IP addresses
      • From: Graff <email@hidden>
References: 
 >Sorting IP addresses (From: Marconi <email@hidden>)

  • Prev by Date: Re: [OT] Finding Mail.app rules and junk filters
  • Next by Date: Re: Sorting IP addresses
  • Previous by thread: Re: Sorting IP addresses
  • Next by thread: Re: Sorting IP addresses
  • Index(es):
    • Date
    • Thread