Diffs
Net_MobileCIDR/trunk/Net/MobileCIDR.php
@@ -1,4 +1,13 @@
<?php
+/**
+* Net_MobileCIDR
+* Scraping Gateway
+*
+* @version: 0.1.1 <2008/12/19 7:29>
+* @package: Net_MobileCIDR
+* @author: Shuhei Tanuma <shuhei.tanuma at gmail.com>
+**/
+
require dirname(__FILE__) . "/MobileCIDR/Interface.php";
require dirname(__FILE__) . "/MobileCIDR/Carrier.php";
require dirname(__FILE__) . "/MobileCIDR/DoCoMo.php";
@@ -8,27 +17,28 @@
require dirname(__FILE__) . "/MobileCIDR/Emobile.php";
class Net_MobileCIDR{
- const DoCoMo = 1;
- const SoftBank = 2;
- const EZweb = 3;
- const Willcom = 4;
- const EMobile = 5;
+ const Version = "0.1.1";
+ 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:
+ case Net_MobileCIDR::DOCOMO:
return new Net_MobileCIDR_DoCoMo();
break;
- case Net_MobileCIDR::SoftBank:
+ case Net_MobileCIDR::SOFTBANK:
return new Net_MobileCIDR_SoftBank();
break;
- case Net_MobileCIDR::EZweb:
+ case Net_MobileCIDR::EZWEB:
return new Net_MobileCIDR_EZweb();
break;
- case Net_MobileCIDR::Willcom:
+ case Net_MobileCIDR::WILLCOM:
return new Net_MobileCIDR_Willcom();
break;
- case Net_MobileCIDR::EMobile:
+ case Net_MobileCIDR::EMOBILE:
return new Net_MobileCIDR_Emobile();
break;
}
Net_MobileCIDR/trunk/Net/MobileCIDR/EZweb.php
@@ -3,16 +3,7 @@
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;
+ protected function makeCIDR($array){
+ return $array[1] . $array[2];
}
}
Net_MobileCIDR/trunk/Net/MobileCIDR/Emobile.php
@@ -2,16 +2,4 @@
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
@@ -9,16 +9,4 @@
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/Willcom.php
@@ -2,16 +2,4 @@
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
@@ -2,12 +2,16 @@
abstract class Net_MobileCIDR_Carrier implements Net_MobileCIDR_Interface{
protected $target_url;
protected $regexp;
- protected $useragent = "PHP/Net_MobileCIDR/1.0";
+ protected $useragent = "PHP %s/Net_MobileCIDR/%s";
+ public function __construct(){
+ $this->useragent = sprintf($this->useragent,phpversion(),Net_MobileCIDR::Version);
+ }
+
public function getContents(){
$url_params = parse_url($this->target_url);
- $sock = fsockopen($url_params['host'],80,$errno,$errstr,3);
+ $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);
@@ -36,6 +40,20 @@
public function getIPAddresses(){
return $this->Scrape();
}
-
- abstract function Scrape();
+
+ protected function makeCIDR($array){
+ return $array[1];
+ }
+
+ public function Scrape(){
+ $result = array();
+ preg_match_all($this->regexp,$this->getContents(),$matches,PREG_SET_ORDER);
+ foreach($matches as $item){
+ if(Net_MobileCIDR::checkCIDR($this->makeCIDR($item))){
+ $result[] = $this->makeCIDR($item);
+ }
+ }
+
+ return $result;
+ }
}
\ No newline at end of file
Net_MobileCIDR/trunk/Net/MobileCIDR/SoftBank.php
@@ -2,16 +2,4 @@
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;
- }
}