« 版本问题 好累 | Main | 各位老师 可以去blog.edu.cn申请blog »
November 21, 2004
IPCN 国家地区代理列表恢复 http://proxy.ipcn.org/country/
版权声明:可以任意转载,转载时请务必以超链接形式标明文章原始出处和作者信息及本声明。 https://windtear.net/archives/2004/11/21/000262.html IPCN 国家地区代理列表恢复 http://proxy.ipcn.org/country/
之前相当一段瞬间都只更新了国内的 昨天连 bitkeeper 突然连不上 以为被封了 于是就想找美国代理 再于是就去恢复了 IPCN 国家地区代理列表 这里写两点mysql的东西 perl & php 1. perl 有 DBI module 连 mysql 时间处理 mysql自身 有 CURRENT_TIMESTAMP ( mysql: http://www.mysql.com/ 有很方便的查询接口 php: http://www.php.net 也有很方便的查询接口 perl: perldoc module 有 http://search.cpan.org ) mysql> desc proxy; +---------+------------------+------+-----+---------------------+----------------+ | Field | Type | Null | Key | Default | Extra | +---------+------------------+------+-----+---------------------+----------------+ | id | int(10) unsigned | | PRI | NULL | auto_increment | | proxy | varchar(80) | | | | | | port | varchar(5) | | | | | | country | char(2) | | | | | | type | char(1) | | | | | | time | datetime | | | 0000-00-00 00:00:00 | | +---------+------------------+------+-----+---------------------+----------------+ 6 rows in set (0.00 sec) #!/usr/bin/perl # # Proxy List # by windtear # $WWWDIR="/var/www/ipcn.org/proxy"; $date = `date +%Y%m%d-%H%M`; chomp $date; $sqlflag=1; if (@ARGV) { if ("$ARGV[0]" eq "-h" || "$ARGV[0]" eq "--help") { print "$0 [20031116-0145] [0/1]\n"; exit; } if ( ! -f "$ARGV[0]" ) { print "$ARGV[0] not exist!\n"; exit; } if ($ARGV[1] ne "") { $sqlflag=$ARGV[1]; } #@messages = `grep pp $ARGV[0]`; #@messages = <>; $filename=$ARGV[0]; print "doing ".$filename."\n"; } else { print "geting proxy data\n"; $filename=$date; } if ($sqlflag==1) { use DBI(); # Connect to the database. $dbh = DBI->connect("DBI:mysql:database=dbname;host=dbhost", "dbuser", "dbpassword", {'RaiseError' => 1}); } $proxysize = (stat("$filename"))[7]; if ($proxysize > 1000) { open(IN, "$filename") || die("can't open $filename"); while (<IN>){ chomp($_); $temp=$temp.$_; }; if ($sqlflag==1) { $sth = $dbh->prepare("insert into db (proxy,time) values ('$proxy',CURRENT_TIMESTAMP)"); $sth->execute(); } if ($sqlflag==1) { #$sth->finish(); # Disconnect from the database. $dbh->disconnect(); } 2. php 里面 时间:date("Y-m-d H:i:s"); mysql_pconnect($this->Host, $this->User, $this->Password); (前面贴过那个 db_mysql.php 一个类) $db = db_mysql::connect($syscfg['mysql']); $count = $db->query_first("SELECT COUNT(*) FROM `db` WHERE ip = '$ip'"); $count = intval($count[0]); if ($count > 0) { } $time = date("Y-m-d H:i:s"); $db->query("insert into db VALUES ('','$time')"); if($db->affected_rows() == 1) {print "succeed submit"; exit; } $db->close(); |
Posted by windtear at November 21, 2004 11:27 PM