Skip to content

Instantly share code, notes, and snippets.

@zhiyelee
Created March 31, 2012 02:41
Show Gist options
  • Save zhiyelee/2258799 to your computer and use it in GitHub Desktop.
Save zhiyelee/2258799 to your computer and use it in GitHub Desktop.
twtter get ip
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Get IP</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<?php
$domains = array('api.twitter.com', 'twitter.com');
$get_ip_count = 8;
// 编码:utf-8
function getIP($domain)
{
if (!$domain)
{
exit('请输入域名!');
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://who.is/tools/ping/');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)");
curl_setopt($ch, CURLOPT_POSTFIELDS, 'host=' . $domain);
$recvData = curl_exec($ch);
curl_close($ch);
if ($recvData)
{
$matchcount = preg_match("/PING.*?\(([\d.]+)\)/i", $recvData, $matches);
if ($matchcount > 0)
{
return $matches[1];
}
}
return false;
}
function emnuDomains()
{
global $domains, $get_ip_count;
foreach($domains as $domain)
{
$ipcount = 0;
echo 'REM “' . $domain . '”的IP:<br>';
for ($i = 0; $i < $get_ip_count * 2 && $ipcount < $get_ip_count; $i++)
{
if ($newip = getIP($domain))
{
$ipcount++;
echo $newip . ' <a href="https://'.$newip.'">测试连接</a>'.' <br>';
}
}
}
echo '<br>直接点IP后的“测试连接”,测试该IP是否可用。';
echo '<br>若均不可用,请<a href="getip.php">刷新</a>本页重新获取。';
echo '<br>将测试后可用的IP以如下形式添加到hosts中。<br/>';
echo '+----------+----------+----------+<br/>';
echo ' #twitter <br/>
199.59.148.31 twitter.com<br/>
199.59.148.31 api.twitter.com<br/>
199.59.148.31 search.twitter.com<br/>
199.59.148.31 www.twitter.com<br/>
199.59.148.31 search.twitter.com<br/>
199.59.148.31 integratedsearch.twitter.com<br/>';
echo '+----------+----------+----------+<br/>';
}
emnuDomains();
?>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment