Your Ad Here
首页 | 编程语言 | 网站建设 | 游戏天堂 | 冲浪宝典 | 网络安全 | 操作系统 | 软件时空 | 硬件指南 | 病毒相关 | IT 认证
软讯网络 > 网站建设 > 网页制作 > Python实现的在线保持
【标  题】:Python实现的在线保持
【关键字】:Python
【来  源】:http://blog.csdn.net/gashero/archive/2006/07/06/885412.aspx

Python实现的在线保持

Your Ad Here

Python实现的在线保持
偶所在的校园网,如果一段时间没有下载流量则自动断网,所以编写此程序定期访问网络,下载一些无关紧要的数据,来保持网络链接。

 

 

 

# -*- coding: gbk -*-

from socket import *
import time

GET_DATA="""\
GET / HTTP/1.1
Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, application/x-shockwave-flash, */*
Accept-Language: zh-cn
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; Maxthon)
Host: %s
Connection: Keep-Alive

"""

siteList=[
 ('202.108.22.5',80),
 ('61.135.133.103',80),
 ('71.5.7.138',80),
 ('216.109.112.135',80),
 ('202.108.9.16',80)
 ]

def loop():
 global siteList
 for addr,port in siteList:
  data=''
  try:
   s=socket(AF_INET,SOCK_STREAM)
   s.settimeout(30) #超时30秒
   s.connect((addr,port))
   s.send(GET_DATA%addr)
   data=s.recv(64)
   if data=='':
    print 'IP: %s'%addr+" can't connect!"
   else:
    print 'IP: %s'%addr+" OK !!!!!!!!!!!!!!!!"
  except timeout,detail:
   #超时错误
   print "超时错误 %s"%addr
   pass
  except error,detail:
   #其他Socket错误
   print "其他Socket错误 %s"%addr
   pass
  #except:
   #所有错误
  # pass
  s.close()
  print '='*60
  time.sleep(30)
 return

def main():
 while True:
  loop()
 return

if __name__=='__main__':
 main()

ActionScript按钮事件:【上一篇】
javascript oo object object:【下一篇】
【相关文章】
  • Perl,python,Php超强开发工具Komodo3.5.3注册机
  • python运行
  • python特性
  • Python的两个知名的Web framework
  • python中的测试
  • 重新编译python以后mod_python出问题了
  • 一个Python和C性能对比的好例子
  • 几行用于简繁编码转换的python代码
  • MySQL-python-1.2.0 安装
  • 今天决定去除Python,可能从此我会选择perl.
  • 【随机文章】
  • 水彩画教程-painter 画静物(2)
  • redhat9中的DHCP设置
  • Oracle用户特权管理与审计
  • Java、XML与数据库编程实践(四)
  • 什么是入侵检测
  • fedora core 5的硬盘安装
  • Pro/Engineer Drawing 工程图自动安排尺寸位置
  • AM谁知道怎样下载好看的网页中的flash源代码
  • masm中宏指令的bug
  • 表格
  • 【相关评论】
    没有相关评论
    【发表评论】
    姓名:
    邮件:
    随机码*
    评论*
          
    |  首 页  |  版权声明  |  联系我们   |  网站地图  |
    CopyRight © 2004-2007 bbb软讯网络 All Rigths Reserved.