Marook-Online
* 06.Feb.2012, 14:58 UTC+1
Welcome, Guest. Please login or register.
Username:
Password:

News: Back again Wink
Main Menu
  Navigation
   Downloads
     Tools
     Music Discs
     SMF Mods
     Trainer & Patches
     EgoShare Uploader
   Guestbook
   NoPaste
   User Map
   Gallery
  
   Malware Scan
   Hacker Blacklist
   Find Abusemail
Top Downloads
Support Me !
Help me by donating a small amount!



Advanced search

Google


Pages: [1]   Go Down
0 Members and 1 Guest are viewing this topic. Topic Tools  
Read
19-Nov-2007 17:55
Marook
Administrator
*****
Offline Offline

Joined: 01-Jan-2005
Posts: 224


If you want to store an ip adress in a database, you could store it as 4byte integer (INT), but you must convert the ips into its decimal value.

Code
GeSHi (php-brief):
  1. function ip2dec($ipaddr) {
  2.  $base=explode(".",$ipaddr);
  3.  $decimal=(double) $base[0]*16777216;
  4.  $decimal+=$base[1]*65536;
  5.  $decimal+=$base[2]*256;
  6.  $decimal+=$base[3];
  7.  if($decimal>2147483647) {
  8.    $decimal-=4294967296;
  9.  }
  10.  return (int) $decimal;
  11. }
  12.  
  13. function dec2ip($dec) {
  14.  if($dec<0) {
  15.    $dec=(double) 4294967296+$dec;
  16.  }
  17.  if($dec>16777215) {
  18.    $ip=$dec-(intval($dec/256)*256);
  19.    $dec=(double) intval($dec/256);
  20.  } else $ip="0";
  21.  if($dec>65535) {
  22.    $ip=($dec-(intval($dec/256)*256)).".".$ip;
  23.    $dec=(double) intval($dec/256);
  24.  } else $ip="0.".$ip;
  25.  if($dec>255) {
  26.    $ip=($dec-(intval($dec/256)*256)).".".$ip;
  27.    $dec=(double) intval($dec/256);
  28.  } else $ip="0.".$ip;
  29.  $ip=$dec.".".$ip;
  30.  return (string) $ip;
  31. }
Created by GeSHI 1.0.7.20
Logged
 

Pages: [1]   Go Up
Jump to:  

Theme by webtechnica.net

MHD v2.1 © 2oo8 by Marook
32116 hacking attempts defended!