 |
NickSoft Linux Cookbook Quick howto's, Real live examples.
|
|
View previous topic :: View next topic |
Vote for this article |
1 - useless |
|
0% |
[ 0 ] |
2 - bad |
|
0% |
[ 0 ] |
3 - not so bad |
|
0% |
[ 0 ] |
4 - good |
|
0% |
[ 0 ] |
5 - Excelent |
|
0% |
[ 0 ] |
|
Total Votes : 0 |
|
Author |
Message |
NickSoft Site Admin

Joined: 13 Nov 2006 Posts: 22
|
Posted: Sun May 20, 2007 1:45 pm Post subject: PHP shell 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
ip2hex
Code: | #!/bin/php
<?
printf("%08X\n",ip2long($argv[1]));
?> |
hex2ip
Code: | #!/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
Code: | #!/bin/php
<?
//some hacks to workaround php signed integers
echo base_convert(sprintf("%08X",ip2long($argv[1])),16,10)."\n";
?> |
ip2int
Code: | #!/bin/php
<?
//nothing special - just php function
echo long2ip("3232235777")."\n";
?> |
|
|
Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|