note 85426 added to function.ip2long

From: Date: Fri, 29 Aug 2008 12:19:35 +0000
Subject: note 85426 added to function.ip2long
Groups: php.notes 
Request: Send a blank email to php-notes+get-143980@lists.php.net to get a copy of this message
@Teguh Iskanto Hi, Your solution requires you to store the IP addresses and masks as strings, and also to store the subnet mask being used by your hosts. This is very inefficient. If you stored your network addresses as unsigned Integers, and your masks as TinyInts (i.e. a value between 0 & 32), you could instead do this: select * from networks WHERE inet_aton('10.20.251.130') between ipnumber AND (ipnumber + (POW(2,(32-mask)))-1); Obviously this can be made quicker on very high load systems by storing the broadcast address in the table instead of calculating it on the fly: select * from networks WHERE inet_aton('10.20.251.130') between ipnumber AND broadcast; Nick ---- Server IP: 92.48.100.16 Probable Submitter: 87.127.73.49 ---- Manual Page -- http://www.php.net/manual/en/function.ip2long.php Edit -- https://master.php.net/note/edit/85426 Del: integrated -- https://master.php.net/note/delete/85426/integrated Del: useless -- https://master.php.net/note/delete/85426/useless Del: bad code -- https://master.php.net/note/delete/85426/bad+code Del: spam -- https://master.php.net/note/delete/85426/spam Del: non-english -- https://master.php.net/note/delete/85426/non-english Del: in docs -- https://master.php.net/note/delete/85426/in+docs Del: other reasons-- https://master.php.net/note/delete/85426 Reject -- https://master.php.net/note/reject/85426 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#143980) next »