돌아가기에 급급한 코드이므로 누가 c클래스 파싱부분만 따로 떼서 필요한사람이 정리해서 써라..
굳이 정리는 안해도 잘 돌아간다.
한국어설명
**************************************************
* Code by C.L / Leo Cardia (tech@slrclub.com) *
**************************************************
1. 이 클래스는 후이즈 쿼리루틴 및 파서루틴을 제공하지 않는다
2. 대량의 후이즈 쿼리를 발송할 경우 whois 제공자는 당신의 ip를 차단할수있다
클래스에 대해 : 이 클래스는 whois return value에 속하는 값에 대해 어레이 매스킹으로 리턴해준다
어레이 포맷은 hostip.info 의 sql 디비에 대응할 수 있도록 제공된다.
후이즈의 리턴값이 이러할 경우 -> inetnum: 222.96.0.0 - 222.96.1.0
이 클래스가 만드는 코드는 다음과 같다
array[0]["a"]=222; array[0]["b"]=96; array[0]["c"]=0; array[0]["d"]=0;
array[1]["a"]=222; array[1]["b"]=96; array[1]["c"]=1; array[1]["d"]=0;
1) 후이즈 결과를 php에서 먼저 파싱하여야 한다. (제공하지 않는다)
2) inetnum 라인등을 잡아내야 한다.
( 아래의 코드가 도움이 되길 바란다. 이 코드는 한줄의 문자열에서 ip 어렌지를 잡아낸다 )
$str_ip = explode(":",str_replace(" ","",$ipstrq));
list($start_ip, $end_ip) = explode("-",$str_ip[1]);
3) 이 클래스를 선언한다. ( 파일을 그전에 인클루드하는것을 잊지않길바란다)
$ipr = new ip_array($start_ip, $end_ip);
4) 어레이를 빌드한다
$ipr->make_array();
5) 이제 이 변수를 통해 결과물에 접근할 수 있다
$ipr->insert_address
샘플코드 --
-------- starting sample ----
$ipr = new ip_array("1.253.254.0", "2.0.1.2");
$ipr->make_array();
for ( $i=0; $i<$ipr->g_counter;$i++) {
echo $ipr->insert_address[$i]["a"].".".$ipr->insert_address[$i]["b"].".".$ipr->insert_address[$i]['c'].".".$
ipr->insert_address[$i]["d"]."\n";
}
---------- end sample --------
6) php 액셀레이터 /캐시를 사용할 경우 이 클래스를 선언한 변수를 unset하라. 그렇지 않으면 이 클래스를 통한 대용량의 서브넷 계산등은 메모리 오동작, 문제를 발생시킬수 있다.
English Help
* Code by C.L / Leo Cardia (tech@slrclub.com) *
**************************************************
DISCLAIMER :
1. this class didn't support the whois query routine or parser routine
2. if you put a large connections or queries, whois server is able to block your ip address.
* Sorry! the source code is rousy, i have no time to arrange them
ABOUT : ip_array class returns a masking array from the whois return value;
the return array format compatible with hostip.info's sql database
if whois return value like this -> inetnum: 222.96.0.0 - 222.96.1.0
this class making code are belown
array[0]["a"]=222; array[0]["b"]=96; array[0]["c"]=0; array[0]["d"]=0;
array[1]["a"]=222; array[1]["b"]=96; array[1]["c"]=1; array[1]["d"]=0;
1) you should parse whois result in php
2) grab the inetnum lines
( hope this code helpful, this code extracts a single line string for ip arrange )
$str_ip = explode(":",str_replace(" ","",$ipstrq));
list($start_ip, $end_ip) = explode("-",$str_ip[1]);
3) call this class in this way ( don't forget include file before calling)
$ipr = new ip_array($start_ip, $end_ip);
4) making array
$ipr->make_array();
5) now you can access to result in this variables
$ipr->insert_address
Sample code for a test
-------- starting sample ----
$ipr = new ip_array("1.253.254.0", "2.0.1.2");
$ipr->make_array();
for ( $i=0; $i<$ipr->g_counter;$i++) {
echo $ipr->insert_address[$i]["a"].".".$ipr->insert_address[$i]["b"].".".$ipr->insert_address[$i]['c'].".".$
ipr->insert_address[$i]["d"]."\n";
}
---------- end sample --------
6) you should unset the class definition if your cgi running in php accellater or cache (like turcks mmcache, th
is class may cause memory malfunciton as you define huge class territory)
Source Download (use save link as)
more..
include "iparray.class.php";
function lookup($sip, $eip,$cnt) {
$ipr = new ip_array($sip, $eip);
$ipr->make_array();
if ( $cnt != $ipr->gcounter ) {
echo "$sip - $eip / $cnt Cannot match\n ";
return false;
}
else {
echo "Starting $sip - $eip / $cnt\n ";
}
for ( $ix=0; $ix<$ipr->gcounter;$ix++) {
$a=$ipr->insert_address[$ix]["a"];
$b=$ipr->insert_address[$ix]["b"];
$c=$ipr->insert_address[$ix]["c"];
mysql_query("delete from ip4_$a where b=$b and c=$c",$db);
mysql_query("INSERT INTO ip4_$a (b,c,country,cron) VALUES ($b, $c,113,NOW())",$db);
}
}
//디비접속 알아서 셀프
$fp = fopen("KR_IPv4_data.csv","r");
while ( $data = fgetcsv($fp,100, ",") ) {
$ipcount = intval(str_replace(",","",$data[2]));
lookup($data[0], $data[1], $ipcount);
}
fclose($fp);
맨아래껀 krnic 데이터를 처리해주는 파서고.. 이건 구형 hostip db에 맞도록 제작되어있다..
Posted by LeCieL



