|
|
LXVI. Network FunctionsRequirementsThese functions are available as part of the
standard module, which is always available. InstallationThere is no installation needed to use these
functions, they are part of the PHP core. Runtime Configuration
The behaviour of these functions is affected by settings in php.ini.
Taulu 1. Network Configuration Options Name | Default | Changeable |
---|
define_syslog_variables | "0" | PHP_INI_ALL |
For further details and definition of the PHP_INI_* constants see
ini_set().
Here is a short explanation of the configuration directives.
- define_syslog_variables
boolean
Whether or not to define the various syslog variables (e.g. $LOG_PID,
$LOG_CRON, etc.). Turning it off is a good idea performance-wise. At
runtime, you can define these variables by calling
define_syslog_variables().
Resource TypesT�m� laajennus ei m��rittele yht�k��n resurssi-tyyppi�. Predefined Constants
The constants listed here are always available as part of the PHP core.
Taulu 2. openlog() Options Constant | Description |
---|
LOG_CONS |
if there is an error while sending data to the system logger,
write directly to the system console
| LOG_NDELAY |
open the connection to the logger immediately
| LOG_ODELAY |
(default) delay opening the connection until the first
message is logged
| LOG_PERROR | print log message also to standard error | LOG_PID | include PID with each message |
Taulu 3. syslog() Priorities (in descending order) Constant | Description |
---|
LOG_EMERG | system is unusable | LOG_ALERT | action must be taken immediately | LOG_CRIT | critical conditions | LOG_ERR | error conditions | LOG_WARNING | warning conditions | LOG_NOTICE | normal, but significant, condition | LOG_INFO | informational message | LOG_DEBUG | debug-level message |
Taulu 4. dns_get_record() Options Constant | Description |
---|
DNS_A | IPv4 Address Resource | DNS_MX | Mail Exchanger Resource | DNS_CNAME | Alias (Canonical Name) Resource | DNS_NS | Authoritative Name Server Resource | DNS_PTR | Pointer Resource | DNS_HINFO | Host Info Resource (See
for the meaning of these values) | DNS_SOA | Start of Authority Resource | DNS_TXT | Text Resource | DNS_ANY | Any Resource Record. On most systems
this returns all resource records, however
it should not be counted upon for critical
uses. Try DNS_ALL instead. | DNS_AAAA | IPv6 Address Resource | DNS_ALL | Itteratively query the name server for
each available record type. |
User Contributed Notes Network Functions |
|
oliviert at videotron dot ca
18-Feb-1999 09:31 |
|
If u wanna do one of these function on windows95, u have to install the
lastest winsock before , if else php will crash with a message of
wsock32.dll
()
|
|
philip at cornado dot c()m
04-Jul-2001 09:18 |
|
View a few Networking PHP PEAR classes here :
|
|
philip at cornado dot c()m
04-Jul-2001 09:20 |
|
More socket functions can be seen here :
|
|
philippe-at-cyberabuse.org
15-Dec-2001 02:46 |
|
PHP miss CIDR functions.
This one will convert a CIDR like
this:
0.0.0.0/16 -> 0.0.0.0 - 0.0.255.255
127.0/16 ->
127.0.0.0 - 127.0.255.255
etc...
function cidrconv($net)
{
$start=strtok($net,"/");
$n=3-substr_count($net,
".");
if ($n>0) { for ($i=$n;$i>0;$i--)
$start.=".0";
}
$bits1=str_pad(decbin(ip2long($start)),32,"0","STR_PAD_LEFT");
$net=pow(2,(32-substr(strstr($net,"/"),1)))-1;
$bits2=str_pad(decbin($net),32,"0","STR_PAD_LEFT");
for
($i=0;$i<32;$i++) {
if ($bits1[$i]==$bits2[$i])
$final.=$bits1[$i];
if ($bits1[$i]==1 and $bits2[$i]==0)
$final.=$bits1[$i];
if ($bits1[$i]==0 and $bits2[$i]==1)
$final.=$bits2[$i];
}
return $start." -
".long2ip(bindec($final));
}
|
|
philippe-at-cyberabuse.org
12-Oct-2002 10:49 |
|
... and this one will do the opposite (o return NULL for invalid netblocks)
:
1.0.0.0 1.0.255.255 -> 1.0.0.0/16 1.0.0.0 1.3.255.255 ->
1.0.0.0/14 192.168.0.0 192.168.0.255 ->
192.168.0.0/24
function ip2cidr($ip_start,$ip_end)
{ if(long2ip(ip2long($ip_start))!=$ip_start or
long2ip(ip2long($ip_end))!=$ip_end) return NULL;
$ipl_start=(int)ip2long($ip_start); $ipl_end=(int)ip2long($ip_end); if($ipl_start>0
&& $ipl_end<0) $delta=($ipl_end+4294967296)-$ipl_start; else
$delta=$ipl_end-$ipl_start; $netmask=str_pad(decbin($delta),32,"0","STR_PAD_LEFT"); if(ip2long($ip_start)==0
&& substr_count($netmask,"1")==32) return
"0.0.0.0/0"; if($delta<0 or ($delta>0 &&
$delta%2==0)) return NULL; for($mask=0;$mask<32;$mask++)
if($netmask[$mask]==1)
break; if(substr_count($netmask,"0")!=$mask) return
NULL; return "$ip_start/$mask"; }
|
|
trevor-hemsley at nospam dot dial dot pipex dot com
16-Oct-2002 06:53 |
|
Previous example of IP range to CIDR list does not cope with ranges as well
as the perl Net::Netmask range2cidrlist() function. In PHP this looks
like
<? function imask($this) { // use base_convert not
dechex because dechex is broken and returns 0x80000000 instead of
0xffffffff return base_convert((pow(2,32) - pow(2, (32-$this)))), 10,
16); }
function imaxblock($ibase, $tbit) { while ($tbit
> 0) { $im = hexdec(imask($tbit-1)); $imand = $ibase &
$im; if ($imand !=
$ibase) { break; } $tbit--; } return
$tbit; }
function range2cidrlist($istart, $iend) { // this
function returns an array of cidr lists that map the range given $s =
explode(".", $istart); // PHP ip2long does not handle leading
zeros on IP addresses! 172.016 comes back as 172.14, seems to be treated
as octal! $start = ""; $dot = ""; while
(list($key,$val) = each($s)) { $start =
sprintf("%s%s%d",$start,$dot,$val); $dot =
"."; } $end = ""; $dot = ""; $e
= explode(".",$iend); while (list($key,$val) =
each($e)) { $end =
sprintf("%s%s%d",$end,$dot,$val); $dot =
"."; } $start = ip2long($start); $end =
ip2long($end); $result = array(); while ($end >
$start) { $maxsize = imaxblock($start,32); $x = log($end - $start
+ 1)/log(2); $maxdiff = floor(32 - floor($x)); $ip =
long2ip($start); if ($maxsize < $maxdiff) { $maxsize =
$maxdiff; } array_push($result,"$ip/$maxsize"); $start
+= pow(2, (32-$maxsize)); } return $result; } ?>
|
|
|
| |