测试防火墙源端口

因为要测试防火墙的规则,指定源端口,没有找到合适的发包工具,故用python脚本来模拟

#!/usr/bin/env python
# coding=utf8
# si.hairui, 2016.11.21
# Http Client, Python 2.7.5

import httplib
import sys

HTTP_SERVER_ADDR = "10.1.2.5"
HTTP_SERVER_PORT = 80
HTTP_SERVER_FILE = "/index.html"
HTTP_CLIENT_ADDR = "10.1.2.222"
HTTP_CLIENT_PORT = int(sys.argv[1])

# 请求http服务器,Server端暂时写死,后面增加配置文件
myHttpConn = httplib.HTTPConnection(HTTP_SERVER_ADDR,
                                    HTTP_SERVER_PORT,
                                    source_address = (HTTP_CLIENT_ADDR, HTTP_CLIENT_PORT))
myHttpConn.debuglevel = 0  # 打开调试模式
myHttpConn.request("GET", HTTP_SERVER_FILE)  # 资源路径以“/”开始

myHttpResp = myHttpConn.getresponse()
if 0 == myHttpConn.debuglevel:
    print myHttpResp.status, myHttpResp.reason  # 响应码和状态信息

try:
    # 此处必须读响应内容,如果不读取,buff将溢出!!!
    data1 = myHttpResp.read()
    pass
except:
    print "Exception!"
finally:
    # print data1   # 打印响应内容
    print "HttpClient will be closed!"

myHttpConn.close()     # 关闭连接

指定端口号运行脚本

posted @ 2019-01-15 11:09  mrwuzs  阅读(498)  评论(0编辑  收藏  举报