|

楼主 |
发表于 2007-8-30 17:30:50
|
显示全部楼层
确实想看看别人的代码, 也不用说骗吧.
我用PHP写了个, 需存为UTF-8编码文件:- #!/usr/bin/php
- <?php
- function ipcn_get_token(&$str)
- {
- $ret[0]=-127;
- $ret[1]="";
- if (strlen($str) == 0)
- return $ret;
- $chr = substr($str, 0, 1);
- $str = substr($str, 1);
- $ichr = ord($chr);
- $gchr = ipcn_get_group($ichr);
- $ret[0]= $gchr;
- $ret[1]= $chr;
- while (strlen($str) && $gchr==ipcn_get_group(ord($str{0}))) {
- $ret[1].= $str{0};
- $str = substr($str, 1);
- }
- return $ret;
- }
- function ipcn_split_tokens($str)
- {
- $ret[0]=array();
- $ret[1]=array();
- while (strlen($str)) {
- $tk = ipcn_get_token($str);
- //echo "{".$tk[0].":".$tk[1]."}";
- array_push($ret[0], $tk[0]);
- array_push($ret[1], $tk[1]);
- }
- return $ret;
- }
- function ipcn_get_group($ichr)
- {
- if ($ichr >= ord('a') && $ichr <= ord('z')) return 10;
- if ($ichr >= ord('A') && $ichr <= ord('Z')) return 10;
- if ($ichr == ord('.')) return 10;
- if ($ichr > 127) return 20;
- if ($ichr == ord(' ')) return 40;
- if ($ichr == ord('(')) return 100;
- if ($ichr == ord(')')) return 200;
-
- return 10000;
- }
- function ipcn_getpw($ipcn)
- {
- $tka=ipcn_split_tokens($ipcn);
- $tkg=$tka[0];
- $tks=$tka[1];
- $len = count($tkg);
- $state = 0;
- $passwds = array();
- for ($i=0;$i<$len;++$i) {
- $g = $tkg[$i]; $s=$tks[$i];
- //echo "prestate:$state, now str[$g]:{$s}\n";
- if ($state<100 && strpos($s, "出国代理")!==false) {
- $state=100;
- continue;
- }
- if ($state >= 100 && $state < 1000) {
- if (strcasecmp($s, 'user') == 0 ||
- strcasecmp($s, 'username') == 0||
- strcasecmp($s, 'proxyuser') == 0 )
- $state = 1000; // after username;
- elseif (strpos($s, "用户")!==false)
- $state = 1000;
- continue;
- }
- if ($state == 1000) {
- if ($g == 10 && strcasecmp($s, "proxy") ==0 ) {
- $state = 2000;// after proxy, now seek for password
- }
- continue;
- }
- if ($state == 2000) {
- if (strcasecmp($s, 'pass') == 0 ||
- strcasecmp($s, 'password')==0)
- $state = 3000;
- elseif(strpos($s, "密码") !== false)
- $state =3000;
- continue;
- }
- if ($state >= 3000 && $state < 4000) {
- if ($g == 100) {
- $state = 3100;
- } else if ($g == 10) {
- if ($state == 3100) {
- if (strlen($s) > 2) {
- array_push($passwds, $s);
- $state = 0;
- }
- } else {
- array_push($passwds, $s);
- //echo "get passwd: $s\n";
- $state = 0;
- }
- } else if ($g == 200) {
- $state = 3200;
- }
- continue;
- }
- }
- return $passwds;
- }
- function ipcn_textfrmhtml($html)
- {
- $start="使用自动配置脚本";
- $stop="IE 菜单 工具(T)";
- $html = strstr($html, $start);
- $html = substr($html, 0, strpos($html, $stop));
- $html = preg_replace(array("/<!--.*?-->/",
- "/<\\/?(br|p|div)>/",
- "/<script type=.*?<\\/script>/",
- "/<[^>]*>/",
- ),
- array("","\n", "", "", " "), $html);
- $fs = "abcdefghijklmnopqrstuvwxyz"
- ."ABCDEFGHIJKLMNOPQRSTUVWXYZ";
- $hs ="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
- $fa = str_split($fs, 3);
- $ha = str_split($hs);
- $html = str_replace($fa, $ha, $html);
- $html = html_entity_decode($html, ENT_NOQUOTES, "UTF-8");
- $html = str_replace(" ", " ", $html);
- return $html;
- }
- // first get the html
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_URL, "http://proxy.ipcn.org/");
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
- curl_setopt($ch, CURLOPT_BINARYTRANSFER, true);
- $ipcnhtml = curl_exec($ch);
- if ($ipcnhtml === false) {
- echo curl_error($ch);
- die("\nget html failed!, sorry.\n");
- }
- curl_close($ch);
- $ipcnhtml = iconv("GBK", "UTF-8", $ipcnhtml);
- $ipcntext = ipcn_textfrmhtml($ipcnhtml);
- $passwds = ipcn_getpw($ipcntext);
- if (count($passwds)!=1) {
- print_r($passwds);
- die("sorry, get none or more passwords?\n");
- }
- $passwd = $passwds[0];
- echo "$passwd\n";
- ?>
复制代码 |
|