PHP code sharing for obtaining website geographical location and operating system information

WBOY
Release: 2016-07-25 08:57:58
Original
1192 people have browsed it
This article introduces an example code that uses PHP to obtain the geographical location of a website and operating system-related information. Friends in need can refer to it.

1, php code part

<?php
/**
* 获取网站地理位置
* 获取网站操作系统信息
* edit by bbs.it-home.org
*/
error_reporting(E_ERROR);
header(“content-Type: text/html; charset=gb2312″);
set_time_limit(120);
$host = isset($_POST['url']) ? chop(str_replace(‘http://’,”,$_POST['url'])) : ‘ www.2cto.com ’;
$port = isset($_POST['duankou']) ? chop($_POST['duankou']) : ’80′;
$num  = 10;
function microtime_float()
{
        list($usec, $sec) = explode(” “, microtime());
        return ((float)$usec + (float)$sec);
}
function ip138($url)
{
        $host = ‘www.ip138.com’;
        $fp = @fsockopen($host,80,&$errno,&$errstr,3);
        $get = “GET /ips.asp?ip=”.$url.” HTTP/1.1\r\nHost:”.$host.”\r\nConnection: Close\r\n\r\n”;
        @fputs($fp,$get);
        $data = ”;
        while ($fp && !feof($fp))
        $data .= fread($fp, 1024);
        @fclose($fp);
        $s1 = ‘\<table width\=\”80\%\”  border\=\”0\” align\=\”center”\ cellpadding\=\”0\” cellspacing\=\”0\”\>’;
        $s2 = ‘\<\/table\>’;
        $tmp = array();
        preg_match_all(“/”.$s1.”([^~]*?)”.$s2.”/i”,$data,$tmp);
        $tmp1 = array();
        preg_match_all(“/\<li\>([^~]*?)\<\/li\>/i”,$tmp[0][0],$tmp1);
        return $tmp1[0][0].$tmp1[0][1].$tmp1[0][2];
}
function getsoft($host,$port)
{
        $fp = @fsockopen($host,$port,&$errno,&$errstr,3);
        if(!$fp) return ‘unknown’;
        $get = “GET / HTTP/1.1\r\nHost:”.$host.”\r\nConnection: Close\r\n\r\n”;
        @fputs($fp,$get);
        $data = ”;
        while ($fp && !feof($fp))
        $data .= fread($fp, 1024);
        @fclose($fp);
        $array = explode(“\n”,$data);
        $k = 2;
        for($i = 0;$i < 20;$i++)
        {
                if(stristr($array[$i],’Server’)){$k = $i; break;}
        }
        if(!stristr($array[$k],’Server’)) return ‘unknown’;
        else return str_replace(‘Server’,'服务器软件’,$array[$k]);
}
function ping($host,$port)
{
        $time_start = microtime_float();
        $ip = gethostbyname($host);
        $fp = @fsockopen($host,$port,&$errno,&$errstr,1);
        if(!$fp) return ‘Request timed out.<br />’.”\r\n”;
        $get = “GET / HTTP/1.1\r\nHost:”.$host.”\r\nConnection: Close\r\n\r\n”;
        @fputs($fp,$get);
        @fclose($fp);
        $time_end = microtime_float();
        $time = $time_end – $time_start;
        $time = ceil($time * 1000);
        return ‘Reply from ‘.$ip.’: time=’.$time.’ms<br />’;
}
if(isset($_POST['url']) && isset($_POST['duankou']))
{
        echo ip138($host).’<br /><br />’;
        echo ‘<font color=”#FF0000″>’.getsoft($host,$port).’</font><br /><br />’;
        echo ‘Pinging ‘.$host.’ ['.gethostbyname($host).'] with Port:’.$port.’ of data:<br /><br />’.”\r\n”;
        ob_flush();
        flush();
        for($i = 0;$i < $num;$i++)
        {
                echo ping($host,$port);
                ob_flush();
                flush();
                sleep(1);
        }
}
?>
Copy after login

2, page content part

<form method=”POST”>
域名/IP:<input type=”text” name=”url” value=”<?php echo $host;?>” size=”50″>
端口:<input type=”text” name=”duankou” value=”<?php echo $port;?>” size=”10″>
<input type=”submit” value=”ping”>
</form>
Copy after login

>>>> Articles you may be interested in: PHP Sina interface to query IP geographical location php Tencent IP sharing plan to obtain IP geographical location php gets geographical location by IP PHP gets the geolocation code via IP An example reference for php to obtain geographical location through IP php implementation code to obtain the user’s real IP and geographical location (Taobao IP interface) php gets current geographical location interface based on IP address



source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template