Diffs
Net_MobileCIDR/trunk/Net/MobileCIDR.php
@@ -0,0 +1,53 @@
+<?php
+require dirname(__FILE__) . "/MobileCIDR/Interface.php";
+require dirname(__FILE__) . "/MobileCIDR/Carrier.php";
+require dirname(__FILE__) . "/MobileCIDR/DoCoMo.php";
+require dirname(__FILE__) . "/MobileCIDR/SoftBank.php";
+require dirname(__FILE__) . "/MobileCIDR/EZweb.php";
+require dirname(__FILE__) . "/MobileCIDR/Willcom.php";
+require dirname(__FILE__) . "/MobileCIDR/Emobile.php";
+
+class Net_MobileCIDR{
+ const DoCoMo = 1;
+ const SoftBank = 2;
+ const EZweb = 3;
+ const Willcom = 4;
+ const EMobile = 5;
+
+ public static function Factory($carrier){
+ switch($carrier){
+ case Net_MobileCIDR::DoCoMo:
+ return new Net_MobileCIDR_DoCoMo();
+ break;
+ case Net_MobileCIDR::SoftBank:
+ return new Net_MobileCIDR_SoftBank();
+ break;
+ case Net_MobileCIDR::EZweb:
+ return new Net_MobileCIDR_EZweb();
+ break;
+ case Net_MobileCIDR::Willcom:
+ return new Net_MobileCIDR_Willcom();
+ break;
+ case Net_MobileCIDR::EMobile:
+ return new Net_MobileCIDR_Emobile();
+ break;
+ }
+ }
+
+ public static function checkCIDR($ip){
+ list($ip,$mask) = explode("/",$ip);
+
+ if(isset($ip) && ($mask > 0 && $mask <= 32)){
+ $iplist = explode(".",$ip);
+ if(count($iplist) == 4){
+ for($i=0; $i<=4;$i++)
+ if(!($iplist[$i] >= 0x0 && $iplist[$i] <=0xff)) return false;
+ }else{
+ return false;
+ }
+ return true;
+ }else{
+ return false;
+ }
+ }
+}
Net_MobileCIDR/trunk/Net/MobileCIDR/EZweb.php
@@ -0,0 +1,18 @@
+<?php
+class Net_MobileCIDR_EZweb extends Net_MobileCIDR_Carrier{
+ protected $target_url = "http://www.au.kddi.com/ezfactory/tec/spec/ezsava_ip.html";
+ protected $regexp = '!<td>\s*<div class="TableText">(.*?)</div>\s*</td>\s*<td>\s*<div class="TableText">(.*?)</div>\s*</td>!';
+
+ public function Scrape(){
+ $result = array();
+ preg_match_all($this->regexp,$this->getContents(),$matches,PREG_SET_ORDER);
+
+ foreach($matches as $item){
+ if(Net_MobileCIDR::checkCIDR($item[1] . $item[2])){
+ $result[] = $item[1] . $item[2];
+ }
+ }
+
+ return $result;
+ }
+}
Net_MobileCIDR/trunk/Net/MobileCIDR/Emobile.php
@@ -0,0 +1,17 @@
+<?php
+class Net_MobileCIDR_EMobile extends Net_MobileCIDR_Carrier{
+ protected $target_url = "http://developer.emnet.ne.jp/ipaddress.html";
+ protected $regexp = '!<div align="center">([\d\./]+)</div>!';
+
+ public function Scrape(){
+ $result = array();
+ preg_match_all($this->regexp,$this->getContents(),$matches,PREG_SET_ORDER);
+ foreach($matches as $item){
+ if(Net_MobileCIDR::checkCIDR($item[1])){
+ $result[] = $item[1];
+ }
+ }
+
+ return $result;
+ }
+}
Net_MobileCIDR/trunk/Net/MobileCIDR/DoCoMo.php
@@ -0,0 +1,24 @@
+<?php
+class Net_MobileCIDR_DoCoMo extends Net_MobileCIDR_Carrier{
+ protected $target_url = "http://www.nttdocomo.co.jp/service/imode/make/content/ip/";
+ protected $regexp = '!<li>([\d\./]+)</li>!';
+
+ public function getContents(){
+ $regexp = '!<ul class="normal txt">.+?</ul>!s';
+ $data = parent::getContents();
+ preg_match($regexp,$data,$matches);
+ return $matches[0];
+ }
+
+ public function Scrape(){
+ $result = array();
+ preg_match_all($this->regexp,$this->getContents(),$matches,PREG_SET_ORDER);
+ foreach($matches as $item){
+ if(Net_MobileCIDR::checkCIDR($item[1])){
+ $result[] = $item[1];
+ }
+ }
+
+ return $result;
+ }
+}
Net_MobileCIDR/trunk/Net/MobileCIDR/Interface.php
@@ -0,0 +1,4 @@
+<?php
+interface Net_MobileCIDR_Interface{
+ public function getIPAddresses();
+}
Net_MobileCIDR/trunk/Net/MobileCIDR/Willcom.php
@@ -0,0 +1,17 @@
+<?php
+class Net_MobileCIDR_Willcom extends Net_MobileCIDR_Carrier{
+ protected $target_url = "http://www.willcom-inc.com/ja/service/contents_service/club_air_edge/for_phone/ip/";
+ protected $regexp = '!<font size="2">([\d\./]+)</font>!';
+
+ public function Scrape(){
+ $result = array();
+ preg_match_all($this->regexp,$this->getContents(),$matches,PREG_SET_ORDER);
+ foreach($matches as $item){
+ if(Net_MobileCIDR::checkCIDR($item[1])){
+ $result[] = $item[1];
+ }
+ }
+
+ return $result;
+ }
+}
Net_MobileCIDR/trunk/Net/MobileCIDR/Carrier.php
@@ -0,0 +1,41 @@
+<?php
+abstract class Net_MobileCIDR_Carrier implements Net_MobileCIDR_Interface{
+ protected $target_url;
+ protected $regexp;
+ protected $useragent = "PHP/Net_MobileCIDR/1.0";
+
+ public function getContents(){
+ $url_params = parse_url($this->target_url);
+
+ $sock = fsockopen($url_params['host'],80,$errno,$errstr,3);
+ if($sock){
+ $request = sprintf("GET /%s%s HTTP/1.0\r\n",$url_params['path'],
+ (isset($url_params['query'])) ? "?" . $url_params['query'] : null);
+ $request .= sprintf("Host: %s\r\n",$url_params['host']);
+ $request .= sprintf("UserAgent: %s\r\n",$this->useragent);
+ $request .= sprintf("\r\n");
+
+ fwrite($sock,$request);
+ $flag = false;
+ $data = "";
+ while(!feof($sock)){
+ $line = fgets($sock);
+ if(!flag){
+ if($line == "\r\n"){
+ $flag = true;
+ }
+ }else{
+ $data .= $line;
+ }
+ }
+ }
+
+ return $data;
+ }
+
+ public function getIPAddresses(){
+ return $this->Scrape();
+ }
+
+ abstract function Scrape();
+}
\ No newline at end of file
Net_MobileCIDR/trunk/Net/MobileCIDR/SoftBank.php
@@ -0,0 +1,17 @@
+<?php
+class Net_MobileCIDR_SoftBank extends Net_MobileCIDR_Carrier{
+ protected $target_url = "http://creation.mb.softbank.jp/web/web_ip.html";
+ protected $regexp = '!<td bgcolor="#eeeeee"> ([\d\./]+)</td>!';
+
+ public function Scrape(){
+ $result = array();
+ preg_match_all($this->regexp,$this->getContents(),$matches,PREG_SET_ORDER);
+ foreach($matches as $item){
+ if(Net_MobileCIDR::checkCIDR($item[1])){
+ $result[] = $item[1];
+ }
+ }
+
+ return $result;
+ }
+}