Convert Hex IP to Dec

By gennarino on Apr 29, 2020

/* 
Routine to convert an Hex IP in a Decimal IP

Use:     %res = $Hex2IP( hex_IP )

Alias h2d is used for test purpose only.
Try::     /h2d 598af63b
Output:     89.138.246.59
*/

alias h2d   {
  var %a = $Hex2IP( $1 )
  .echo 4 -a %a
}

alias -l Hex2IP {
  var %id = $1

  var %d1 = $mid(%id, 0, 2)
  var %d2 = $mid(%id, 3, 2)
  var %d3 = $mid(%id, 5, 2)
  var %d4 = $mid(%id, 7, 2)

  return  $base( %d1,16,10 ) $+ . $+ $base( %d2,16,10 ) $+ . $+ $base( %d3,16,10 ) $+ . $+ $base( %d4,16,10 )
}

Comments

Sign in to comment.
PurpleCow   -  Apr 30, 2020

Or you can make it shorter this way:

alias hex2ip { return $longip($base($1,16,10)) }
alias ip2hex { return $base($longip($1),10,16) } 
 Respond  
Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.