<?php
class Files
{
public static function getUrlContentList($url, $ip = '')
{
if (empty ( $url )) {
return false;
}
$parsed = parse_url ( $url );
$host = $parsed ['host'];
$uri = $parsed ['path'] ? $parsed ['path'] : '';
$uri .= $parsed ['query'] ? '?' . $parsed ['query'] : '';
$uri .= $parsed ['fragment'] ? '#' . $parsed ['fragment'] : '';
unset ( $parsed );
$ips = gethostbynamel ( $host );
$rets = array ();
if (! empty ( $ip )) {
if (! in_array ( $ip, $ips )) {
return false;
} else {
$rets [] = self::HttpVisit ( $ip, $host, $uri );
return $rets;
}
}
foreach ( $ips as $ip ) {
$rets [] = self::HttpVisit ( $ip, $host, $uri );
}
return $rets;
}
public static function HttpVisit($ip, $host, $uri)
{
$errstr = '';
$errno = '';
$fp = fsockopen ( $ip, 80, $errno, $errstr, 90 );
if (! $fp) {
return false;
} else {
$out = "GET {$uri} HTTP/1.1/r/n";
$out .= "Host:{$host}/r/n";
$out .= "Connection: close/r/n/r/n";
fputs ( $fp, $out );
while ( $line = fread ( $fp, 4096 ) ) {
$response .= $line;
}
fclose ( $fp );
//去掉Header头信息
$pos = strpos ( $response, "/r/n/r/n" );
$response = substr ( $response, $pos + 4 );
return $response;
}
}
}
/*
调用方法:
$data = Files::getUrlContentList('http://xxx/xxx.htm', '192.168.xxx.xxx');
print_r($data);
*/
?>
如果一个域名对应多个IP,取得指定IP下的网页内容
最新推荐文章于 2024-06-19 23:36:41 发布