• 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: Need to translate IP addresses from hex value to dotted
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Need to translate IP addresses from hex value to dotted


  • Subject: Re: Need to translate IP addresses from hex value to dotted
  • From: "Arthur J Knapp" <email@hidden>
  • Date: Thu, 15 Mar 2001 16:26:10 -0500

> Date: Wed, 14 Mar 2001 23:10:42 -0700
> From: "Marc K. Myers" <email@hidden>
> Subject: Re: Need to translate IP addresses from hex value to dotted >

>> From: "Arthur J Knapp" <email@hidden>
>> > From: Michelle Steiner <email@hidden>
>> > set val to (offset of (character j of theitem) in "123456789ABCDEF")
>> > Note: the hex alpha characters must be in upper case for this script to
>> > work.
>> set val to (offset of (character j of theitem) in "123456789ABCDEF")
>> if val = 0 then
>> set val to (offset of (character j of theitem) in "abcdef") + 9
>> end if



> Hey! Wait a minute! Isn't "0" still a valid hex character? Someone
> needs to stand up for the "0"s of the world!

Whoops! Both Michelle and I missed this.


Having reviewed the original posting, I have put together
my own solution:




set input to "00FF00FF"


set hexList to Hex2IntList(input)

set text item delimiters to {"."}
set IPAddress to hexList as string
set text item delimiters to {""}

IPAddress -- > "0.255.0.255"



property sHexParse : "0.1.2.3.4.5.6.7.8.9AaBbCcDdEeFf"

on Hex2Int(hexString)
-- hexString == [0-9A-Fa-f]+

set {int, pow} to {0, 0}
repeat with char in hexString
set int to int + (((offset of char in sHexParse) div 2) * (16 ^ pow))

set pow to pow + 1
end repeat

return int
end Hex2Int

on Hex2IntList(hexString)

set lst to {}
repeat with x from 1 to length of hexString by 2
set end of lst to ,
Hex2Int(text x thru (x + 1) of hexString)
end repeat

return lst
end Hex2IntList




Arthur J. Knapp
http://www.stellarvisions.com
mailto:email@hidden

Hey, check out:
http://MacScripter.net/


  • Prev by Date: Re: Retrospect Client
  • Next by Date: Re: applescript-users digest, Vol 2 #501 - 14 msgs
  • Previous by thread: Re: applescript-users digest, Vol 2 #501 - 14 msgs
  • Next by thread: Re: Startup Items applets problem
  • Index(es):
    • Date
    • Thread