Need to translate IP addresses from hex value to dotted quad?
Need to translate IP addresses from hex value to dotted quad?
- Subject: Need to translate IP addresses from hex value to dotted quad?
- From: Michelle Steiner <email@hidden>
- Date: Tue, 13 Mar 2001 17:01:45 -0800
Here's a script that will do just that.
--Michelle
set testHexIP to "D867DB2D"
set decimalIP to ""
repeat with i from 1 to 4
set theitem to text (i * 2 - 1) through (i * 2) of testHexIP
log theitem
set sum to 0
repeat with j from 2 to 1 by -1
set val to (offset of (character j of theitem) in "123456789ABCDEF")
set sum to sum + val * (16 ^ -(j - 2))
end repeat
set decimalIP to decimalIP & sum & "."
end repeat
set decimalIP to text 1 through -1 of decimalIP
-->"216.103.219.45."
Note: the hex alpha characters must be in upper case for this script to
work.
----------------------------------------------------------------------
| Michelle Steiner | We're not human beings having a spiritual |
| | experience. We're spiritual beings |
| email@hidden | having a human experience. |
----------------------------------------------------------------------