———

 
Translations of this page:

PHP scripts for converting IPs

The next two scripts are used for converting hex ips used by phpbb2 in databases. Ex. hex ip for 192.168.1.1 is C0A80101

#!/bin/php
<?
  printf("%08X\n",ip2long($argv[1]));

hex2ip

#!/bin/php
<?
  echo long2ip(hexdec($argv[1]))."\n";

And these are used for converting IPs to integer and back. Ex. integer ip for 192.168.1.1 is 3232235777

ip2int

#!/bin/php
<?
//some hacks to workaround php signed integers
  echo base_convert(sprintf("%08X",ip2long($argv[1])),16,10)."\n";

ip2int

#!/bin/php
<?
//nothing special - just php function
  echo long2ip("3232235777")."\n";
 
lcb/scripts/php-scripts-for-converting-ips.txt · Last modified: 09.22.2008 15:02 by npelov
 
Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki