Created
April 28, 2010 06:28
-
-
Save slywalker/381799 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class MobileIP { | |
var $url = array( | |
'DoCoMo' => 'http://www.nttdocomo.co.jp/service/imode/make/content/ip/index.html', | |
'SoftBank' => 'http://developers.softbankmobile.co.jp/dp/tech_svc/web/ip.php', | |
'AU' => 'http://www.au.kddi.com/ezfactory/tec/spec/ezsava_ip.html', | |
'WILLCOM' => 'http://www.willcom-inc.com/ja/service/contents_service/club_air_edge/for_phone/ip/', | |
); | |
function getAllIP() | |
{ | |
foreach ($this->url as $ua=>$url) { | |
echo $ua.': <a href="'.$url.'">'.$url.'</a>'."\n"; | |
$this->formatArrayValue($this->getIP($url)); | |
} | |
} | |
function getIP($url, $targrtEncode = 'SJIS', $internalEncode = 'UTF-8') | |
{ | |
$htmlText = file_get_contents($url); | |
$htmlText = mb_convert_encoding($htmlText, 'UTF-8', $targrtEncode); | |
$htmlText = str_replace("\r\n","\n", $htmlText); | |
$htmlText = str_replace("\n","", $htmlText); | |
preg_match_all("/([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}(.*?)\/[0-9]{1,3})/", $htmlText, $result); | |
foreach ($result[0] as $key=>$value) { | |
$result[0][$key] = str_replace($result[2][$key],"", $result[1][$key]); | |
} | |
return array_unique($result[0]); | |
} | |
function formatArrayValue($array) | |
{ | |
echo '<pre>'; | |
foreach ($array as $value) { | |
echo "'".$value."',\n"; | |
} | |
echo '</pre>'; | |
} | |
} | |
header("Content-Type: text/html; charset=UTF-8"); | |
$mobile = new MobileIP(); | |
$mobile->getAllIP(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment