国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 編程 > Python > 正文

python實(shí)現(xiàn)探測(cè)socket和web服務(wù)示例

2020-02-23 05:17:38
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

操作系統(tǒng):linux
軟件環(huán)境:Python 2.7.3

用法:
代碼如下:
$ ./MonSocket.py
# This is check the URI or Socket of the script  #
Usage:
      ./MonSocket.py -d URL; This is Http protocol
      ./MonSocket.py -s socket IP or domain; This is Socket protocol
      ./MonSocket.py -p port; This is Socket port
      ./MonSocket.py -n ; Total number of requests
      ./MonSocket.py -c ; Number of concurrent requests
      ./MonSocket.py -t ; Timeout time(s),socket default is 1s,http default is 5s
For exampale: ./MonSocket.py -d www.weibo.com/index.php -n 200 -c 10 -t 2
For exampale: ./MonSocket.py -s 10.210.214.249 -p 80 -n 200 -c 50 -t 3

代碼:
代碼如下:
#!/usr/bin/env python
# encoding: utf-8

#
# Write by 飛奔的蝸牛-Bob

import os,sys
import getopt,re
import socket,threading,urllib2

def usage():
        print '# This is check the URI or Socket of the script  #'
        print 'Usage:'
        print "      %s -d URL; This is Http protocol" %sys.argv[0]
 print "      %s -s socket IP or domain; This is Socket protocol" %sys.argv[0]
 print "      %s -p port; This is Socket port" %sys.argv[0]
 print "      %s -n ; Total number of requests" %sys.argv[0]
 print "      %s -c ; Number of concurrent requests" %sys.argv[0]
 print "      %s -t ; Timeout time(s),socket default is 1s,http default is 5s" %sys.argv[0]
        print "For exampale: %s -d www.weibo.com/index.php -n 200 -c 10 -t 2" %sys.argv[0]
 print "For exampale: %s -s 10.210.214.249 -p 80 -n 200 -c 50 -t 3" %sys.argv[0]

def Detect_url(url,sign):
 if timeout:
  time = int(timeout)
 else:
  time = 5
 urllib2.socket.setdefaulttimeout(time)
 request = urllib2.Request('http://%s' %(url))
 try:
  ret = urllib2.urlopen(request)
 except urllib2.URLError,e:
  if hasattr(e,"reason"):
   port_timeout.append('1')
  elif hasattr(e,"code"):
   if re.findall('^3/d*','%s' %e.code):
    port_normal.append('1')
   if re.findall('^404/d*','%s' %e.code):
    port_404.append('1')
                        if re.findall('^403/d*','%s' %e.code):
                                port_403.append('1')

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 陈巴尔虎旗| 绩溪县| 阿鲁科尔沁旗| 安岳县| 达拉特旗| 宝丰县| 辽阳市| 视频| 光泽县| 张家港市| 大足县| 陆良县| 海安县| 金川县| 平定县| 天镇县| 宿迁市| 安化县| 玉门市| 漠河县| 凤山县| 通州区| 丹寨县| 新宁县| 和硕县| 视频| 东阿县| 安阳县| 辽阳县| 永福县| 徐州市| 井陉县| 旺苍县| 清苑县| 淄博市| 景洪市| 宁国市| 锡林郭勒盟| 建始县| 乐昌市| 临夏市|