ping.php
来自「PHP 知识管理系统(基于树结构的知识管理系统), 英文原版的PHP源码。」· PHP 代码 · 共 1,099 行 · 第 1/3 页
PHP
1,099 行
$loss = explode(' ', $stats[2]);
$this->_loss = (int)$loss[1];
$round_trip = explode('/', str_replace('=', '/', substr($this->_raw_data[$raw_data_len - 1], 0, -3)));
$this->_round_trip['min'] = (float)ltrim($round_trip[3]);
$this->_round_trip['avg'] = (float)$round_trip[4];
$this->_round_trip['max'] = (float)$round_trip[5];
$this->_round_trip['stddev'] = NULL; /* no stddev */
} /* function _parseResultdarwin() */
/**
* Parses the output of HP-UX' ping command
*
* @access private
*/
function _parseResulthpux()
{
$parts = array();
$raw_data_len = count($this->_raw_data);
$icmp_seq_count = $raw_data_len - 5;
/* loop from second elment to the fifths last */
for($idx = 1; $idx <= $icmp_seq_count; $idx++) {
$parts = explode(' ', $this->_raw_data[$idx]);
$this->_icmp_sequence[(int)substr($parts[4], 9, strlen($parts[4]))] = (int)substr($parts[5], 5, strlen($parts[5]));
}
$this->_bytes_per_request = (int)$parts[0];
$this->_bytes_total = (int)($parts[0] * $icmp_seq_count);
$this->_target_ip = NULL; /* no target ip */
$this->_ttl = NULL; /* no ttl */
$stats = explode(',', $this->_raw_data[$raw_data_len - 2]);
$transmitted = explode(' ', $stats[0]);
$this->_transmitted = (int)$transmitted[0];
$received = explode(' ', $stats[1]);
$this->_received = (int)$received[1];
$loss = explode(' ', $stats[2]);
$this->_loss = (int)$loss[1];
$round_trip = explode('/', str_replace('=', '/',$this->_raw_data[$raw_data_len - 1]));
$this->_round_trip['min'] = (int)ltrim($round_trip[3]);
$this->_round_trip['avg'] = (int)$round_trip[4];
$this->_round_trip['max'] = (int)$round_trip[5];
$this->_round_trip['stddev'] = NULL; /* no stddev */
} /* function _parseResulthpux() */
/**
* Parses the output of AIX' ping command
*
* @access private
*/
function _parseResultaix()
{
$parts = array();
$raw_data_len = count($this->_raw_data);
$icmp_seq_count = $raw_data_len - 5;
/* loop from second elment to the fifths last */
for($idx = 1; $idx <= $icmp_seq_count; $idx++) {
$parts = explode(' ', $this->_raw_data[$idx]);
$this->_icmp_sequence[(int)substr($parts[4], 9, strlen($parts[4]))] = (int)substr($parts[6], 5, strlen($parts[6]));
}
$this->_bytes_per_request = (int)$parts[0];
$this->_bytes_total = (int)($parts[0] * $icmp_seq_count);
$this->_target_ip = substr($parts[3], 0, -1);
$this->_ttl = (int)substr($parts[5], 4, strlen($parts[3]));
$stats = explode(',', $this->_raw_data[$raw_data_len - 2]);
$transmitted = explode(' ', $stats[0]);
$this->_transmitted = (int)$transmitted[0];
$received = explode(' ', $stats[1]);
$this->_received = (int)$received[1];
$loss = explode(' ', $stats[2]);
$this->_loss = (int)$loss[1];
$round_trip = explode('/', str_replace('=', '/',$this->_raw_data[$raw_data_len - 1]));
$this->_round_trip['min'] = (int)ltrim($round_trip[3]);
$this->_round_trip['avg'] = (int)$round_trip[4];
$this->_round_trip['max'] = (int)$round_trip[5];
$this->_round_trip['stddev'] = NULL; /* no stddev */
} /* function _parseResultaix() */
/**
* Parses the output of FreeBSD's ping command
*
* @access private
*/
function _parseResultfreebsd()
{
$raw_data_len = count($this->_raw_data);
$icmp_seq_count = $raw_data_len - 5;
/* loop from second elment to the fifths last */
for($idx = 1; $idx < $icmp_seq_count; $idx++) {
$parts = explode(' ', $this->_raw_data[$idx]);
$this->_icmp_sequence[substr($parts[4], 9, strlen($parts[4]))] = substr($parts[6], 5, strlen($parts[6]));
}
$this->_bytes_per_request = (int)$parts[0];
$this->_bytes_total = (int)($parts[0] * $icmp_seq_count);
$this->_target_ip = substr($parts[3], 0, -1);
$this->_ttl = (int)substr($parts[5], 4, strlen($parts[3]));
$stats = explode(',', $this->_raw_data[$raw_data_len - 2]);
$transmitted = explode(' ', $stats[0]);
$this->_transmitted = (int)$transmitted[0];
$received = explode(' ', $stats[1]);
$this->_received = (int)$received[1];
$loss = explode(' ', $stats[2]);
$this->_loss = (int)$loss[1];
$round_trip = explode('/', str_replace('=', '/', substr($this->_raw_data[$raw_data_len - 1], 0, -3)));
$this->_round_trip['min'] = (float)ltrim($round_trip[4]);
$this->_round_trip['avg'] = (float)$round_trip[5];
$this->_round_trip['max'] = (float)$round_trip[6];
$this->_round_trip['stddev'] = (float)$round_trip[7];
} /* function _parseResultfreebsd() */
/**
* Parses the output of Windows' ping command
*
* @author Kai Schr鰀er <k.schroeder@php.net>
* @access private
*/
function _parseResultwindows()
{
$raw_data_len = count($this->_raw_data);
$icmp_seq_count = $raw_data_len - 8;
/* loop from fourth elment to the sixths last */
for($idx = 1; $idx <= $icmp_seq_count; $idx++) {
$parts = explode(' ', $this->_raw_data[$idx + 2]);
$this->_icmp_sequence[$idx - 1] = (int)substr(end(split('=', $parts[4])), 0, -2);
$ttl = (int)substr($parts[5], 4, strlen($parts[3]));
if ($ttl > 0 && $this->_ttl == 0) {
$this->_ttl = $ttl;
}
}
$parts = explode(' ', $this->_raw_data[1]);
$this->_bytes_per_request = (int)$parts[4];
$this->_bytes_total = $this->_bytes_per_request * $icmp_seq_count;
$this->_target_ip = substr(trim($parts[2]), 1, -1);
$stats = explode(',', $this->_raw_data[$raw_data_len - 3]);
$transmitted = explode('=', $stats[0]);
$this->_transmitted = (int)$transmitted[1];
$received = explode('=', $stats[1]);
$this->_received = (int)$received[1];
$loss = explode('=', $stats[2]);
$this->_loss = (int)$loss[1];
$round_trip = explode(',', str_replace('=', ',', $this->_raw_data[$raw_data_len - 1]));
$this->_round_trip['min'] = (int)substr(trim($round_trip[1]), 0, -2);
$this->_round_trip['avg'] = (int)substr(trim($round_trip[3]), 0, -2);
$this->_round_trip['max'] = (int)substr(trim($round_trip[5]), 0, -2);
} /* function _parseResultwindows() */
/**
* Returns a Ping_Result property
*
* @param string $name property name
* @return mixed property value
* @access public
*/
function getValue($name)
{
return isset($this->$name)?$this->$name:'';
} /* function getValue() */
/**
* Accessor for $this->_target_ip;
*
* @return string IP address
* @access public
* @see Ping_Result::_target_ip
*/
function getTargetIp()
{
return $this->_target_ip;
} /* function getTargetIp() */
/**
* Accessor for $this->_icmp_sequence;
*
* @return array ICMP sequence
* @access private
* @see Ping_Result::_icmp_sequence
*/
function getICMPSequence()
{
return $this->_icmp_sequence;
} /* function getICMPSequencs() */
/**
* Accessor for $this->_bytes_per_request;
*
* @return int bytes per request
* @access private
* @see Ping_Result::_bytes_per_request
*/
function getBytesPerRequest()
{
return $this->_bytes_per_request;
} /* function getBytesPerRequest() */
/**
* Accessor for $this->_bytes_total;
*
* @return int total bytes
* @access private
* @see Ping_Result::_bytes_total
*/
function getBytesTotal()
{
return $this->_bytes_total;
} /* function getBytesTotal() */
/**
* Accessor for $this->_ttl;
*
* @return int TTL
* @access private
* @see Ping_Result::_ttl
*/
function getTTL()
{
return $this->_ttl;
} /* function getTTL() */
/**
* Accessor for $this->_raw_data;
*
* @return array raw data
* @access private
* @see Ping_Result::_raw_data
*/
function getRawData()
{
return $this->_raw_data;
} /* function getRawData() */
/**
* Accessor for $this->_sysname;
*
* @return string OS_Guess::sysname
* @access private
* @see Ping_Result::_sysname
*/
function getSystemName()
{
return $this->_sysname;
} /* function getSystemName() */
/**
* Accessor for $this->_round_trip;
*
* @return array statistical information
* @access private
* @see Ping_Result::_round_trip
*/
function getRoundTrip()
{
return $this->_round_trip;
} /* function getRoundTrip() */
/**
* Accessor for $this->_round_trip['min'];
*
* @return array statistical information
* @access private
* @see Ping_Result::_round_trip
*/
function getMin()
{
return $this->_round_trip['min'];
} /* function getMin() */
/**
* Accessor for $this->_round_trip['max'];
*
* @return array statistical information
* @access private
* @see Ping_Result::_round_trip
*/
function getMax()
{
return $this->_round_trip['max'];
} /* function getMax() */
/**
* Accessor for $this->_round_trip['stddev'];
*
* @return array statistical information
* @access private
* @see Ping_Result::_round_trip
*/
function getStddev()
{
return $this->_round_trip['stddev'];
} /* function getStddev() */
/**
* Accessor for $this->_round_tripp['avg'];
*
* @return array statistical information
* @access private
* @see Ping_Result::_round_trip
*/
function getAvg()
{
return $this->_round_trip['avg'];
} /* function getAvg() */
/**
* Accessor for $this->_transmitted;
*
* @return array statistical information
* @access private
*/
function getTransmitted()
{
return $this->_transmitted;
} /* function getTransmitted() */
/**
* Accessor for $this->_received;
*
* @return array statistical information
* @access private
*/
function getReceived()
{
return $this->_received;
} /* function getReceived() */
/**
* Accessor for $this->_loss;
*
* @return array statistical information
* @access private
*/
function getLoss()
{
return $this->_loss;
} /* function getLoss() */
} /* class Net_Ping_Result */
?>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?