網絡alive主機存活捕捉 一 (下載)

 

  
  
  
  
  1. #!/usr/bin/perl -w 
  2. ######################## 鏈接數據庫, 將數據庫中查找出來的 城市 中文名字和 英文名字 分別放到數組 
  3. use DBI; 
  4. use DBD::mysql; 
  5. # 鏈接數據庫,地址 帳戶 密碼 
  6. my $dbh = DBI -> connect("DBI:mysql:db_iplocate;host=127.0.0.1""admin","admin",{RaiseError=>1}); 
  7. #  sql命令 
  8. my $sth = $dbh->prepare( q{select city_cn,city_en from `gps`}) or die("Cannot prepare statement:", $dbh->errstr(),"\n"); 
  9. # 執行sql命令 
  10. my $rc = $sth->execute() or die("Cannot execute statement:", $sth->errstr(), "\n"); 
  11.  
  12. # 初始化兩個數組,未來用來裝 城市的 中文名字 和 英文名字 
  13. my @city_cn; 
  14. my @city_en; 
  15.  
  16. # 將從mysql獲得的city_cn和city_en放到相應的數組中 
  17. while (my @row = $sth -> fetchrow_array()){ 
  18.     push @city_cn,$row[0]; 
  19.     push @city_en,$row[1]; 
  20. warn($DBI::errstr) if $DBI::err; 
  21. $dbh->disconnect(); 
  22. $sth->finish(); 
  23. ####################### 按照每一個 城市 3個運營商進行生成 相應的命令, 並執行相應的命令,將下載的東西放到 當前目錄的 
  24. # 初始化兩個數組, 用來裝 運營商的 中文名字 和英文名字 
  25. my @isps_cn = ("移動","聯通","電信"); 
  26. my @isps_en = ("ChinaMobile","ChinaUnicom","ChinaTelecom"); 
  27. foreach $i(0..(@city_cn-1)){ 
  28.     foreach $j(0..2) { 
  29.         $page_url = 'wget http://www.5maila.com/ipa.php?' . "$city_cn[$i]" .'%20' . "$isps_cn[$j]" . ' -O ' .  "$city_en[$i]" ."_""$isps_en[$j]" ; 
  30.         print `$page_url`; 
  31.     } 
相關文章
相關標籤/搜索