note 47814 added to function.ip2long

From: Date: Wed, 01 Dec 2004 14:06:00 +0000
Subject: note 47814 added to function.ip2long
Groups: php.notes 
Request: Send a blank email to php-notes+get-81220@lists.php.net to get a copy of this message
I re-wrote the functions from jbothe at hotmail dot com as a little exercise in OO and added a couple of extra functions. <?php //-------------- // IPv4 class class ipv4 { var $address; var $netbits; //-------------- // Create new class function ipv4($address,$netbits) { $this->address = $address; $this->netbits = $netbits; } //-------------- // Return the IP address function address() { return ($this->address); } //-------------- // Return the netbits function netbits() { return ($this->netbits); } //-------------- // Return the netmask function netmask() { return (long2ip(ip2long("255.255.255.255") << (32-$this->netbits))); } //-------------- // Return the network that the address sits in function network() { return (long2ip((ip2long($this->address)) & (ip2long($this->netmask())))); } //-------------- // Return the broadcast that the address sits in function broadcast() { return (long2ip(ip2long($this->network()) | (~(ip2long($this->netmask()))))); } //-------------- // Return the inverse mask of the netmask function inverse() { return (long2ip(~(ip2long("255.255.255.255") << (32-$this->netbits)))); } } $ip = new ipv4("192.168.2.1",24); print "Address: $ip->address()\n"; print "Netbits: $ip->netbits()\n"; print "Netmask: $ip->netmask()\n"; print "Inverse: $ip->inverse()\n"; print "Network: $ip->network()\n"; print "Broadcast: $ip->broadcast()\n"; ?> ---- Manual Page -- http://www.php.net/manual/en/function.ip2long.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+47814 Delete -- http://master.php.net/manage/user-notes.php?action=delete+47814&report=yes Reason: bad code -- http://master.php.net/manage/user-notes.php?action=delete+47814&report=yes&reason=bad+code Reason: spam -- http://master.php.net/manage/user-notes.php?action=delete+47814&report=yes&reason=spam Reason: useless example -- http://master.php.net/manage/user-notes.php?action=delete+47814&report=yes&reason=useless+example Reason: contains commercial links -- http://master.php.net/manage/user-notes.php?action=delete+47814&report=yes&reason=contains+commercial+links Reason: useless note -- http://master.php.net/manage/user-notes.php?action=delete+47814&report=yes&reason=useless+note Reject -- http://master.php.net/manage/user-notes.php?action=reject+47814&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#81220) next »