birmingham@ic.fbi.gov , phoenix@ic.fbi.gov , fbise@leo.gov
NickSoft Linux Cookbook Index NickSoft Linux Cookbook
Quick howto's, Real live examples.
 
 FAQFAQ   SearchSearch   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


PHP shell scripts for converting IPs

 
Post new topic   Reply to topic    NickSoft Linux Cookbook Index -> Other shell scripts
View previous topic :: View next topic  

Vote for this article
1 - useless
0%
 0%  [ 0 ]
2 - bad
0%
 0%  [ 0 ]
3 - not so bad
0%
 0%  [ 0 ]
4 - good
0%
 0%  [ 0 ]
5 - Excelent
0%
 0%  [ 0 ]
Total Votes : 0

Author Message
NickSoft
Site Admin


Joined: 13 Nov 2006
Posts: 22

PostPosted: Sun May 20, 2007 1:45 pm    Post subject: PHP shell scripts for converting IPs Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    NickSoft Linux Cookbook Index -> Other shell scripts All times are GMT
Page 1 of 1

 
Jump to:  
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




MLDb.org Magic Eight Ball Croler Web Search Croler Web Directory Bianca Ryan MyBestMatch.net Microlab.info Digger Services Sofia

Powered by 220V

AbuseIPDB Contributor Badge