python测试网络连通性_PYTHON 测试服务器连通性

#-*-coding:utf-8-*-import osimport sysimport urllib2import pygameimport reimport socketimport subprocess# 输入要测试的site值print "Hello"print pygame.versite=raw_input("Pls Input Your Site:")req = urllib2.Request(‘http://192.168.1.88/cc.txt‘)fd = urllib2.urlopen(req)#http://192.168.1.88/cc.txt连接文件的第一列为site,第二列为电信IP,第三列为联通IP,第四列为域名for i in fd.readlines():i2 = re.match(site,i)if i2:SITE,DXIP,LTIP,DOMAIN=i.split()AGENT,ID=SITE.split(‘_‘)strinfo = re.compile(‘^0*‘)id = strinfo.sub(‘‘,ID)domain = ‘s‘+id+"."+DOMAIN#端口测试for PORT in (1001,1002,1003):s=socket.socket(socket.AF_INET,socket.SOCK_STREAM)s.settimeout(1)DXADDR = (str(DXIP),int(PORT))dxstatus = s.connect_ex(DXADDR)LTADDR = (str(DXIP),int(PORT))ltstatus = s.connect_ex(LTADDR)if dxstatus == 0:print ‘Test DX Connection to %s %s port [tcp] OK‘ % (DXIP,PORT)else:print ‘Test DX Connection to %s %s port [tcp] FAIL‘ % (DXIP,PORT)if ltstatus == 0:print ‘Test LT Connection to %s %s port [tcp] OK‘ % (LTIP,PORT)else:print ‘Test lT Connection to %s %s port [tcp] FAIL‘ % (LTIP,PORT)continue#域名解析测试domainping = subprocess.call("ping -n 1 %s" % domain, shell=True, stdout=open(r‘ping.temp‘,‘w‘), stderr=subprocess.STDOUT)if domainping == 0:print "Domain name resolution %s: is OK" % domainelse:print "Domain name resolution %s: is FAIL" % domain#ping 测试 电信IP不行,就测试联通IPdxping = subprocess.call("ping -n 1 %s" % DXIP, shell=True, stdout=open(r‘ping.temp‘,‘w‘), stderr=subprocess.STDOUT)ltping = subprocess.call("ping -n 1 %s" % LTIP, shell=True, stdout=open(r‘ping.temp‘,‘w‘), stderr=subprocess.STDOUT)if dxping == 0:print "ping DX %s: is OK" % DXIPelse:print "ping DX %s is FAIL" % DXIPif ltping == 0:print "ping LT %s: is OK" % LTIPelse:print "ping LT %s is OK" % LTIP#页面打开测试req1 = urllib2.Request(‘http://%s/aa.jsp‘ % domain)try:urllib2.urlopen(req1)print ‘WebServer OK‘except urllib2.URLError, e:print e.reason#i3=fd1.readlines()#m1=re.search(site,str(i3))raw_input("Pls Input Any Key.......")

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
下面是一个判断复杂的时序动态网络连通性并展示连通性变化的 Python案例,使用了 NetworkX 和 Matplotlib 库: ```python import networkx as nx import matplotlib.pyplot as plt # 创建一个空的有向图 G = nx.DiGraph() # 添加节点 G.add_node(1) G.add_node(2) G.add_node(3) G.add_node(4) G.add_node(5) # 添加边 G.add_edge(1, 2) G.add_edge(2, 3) G.add_edge(3, 1) G.add_edge(4, 5) # 设置节点位置 pos = {1: (0, 0), 2: (1, 1), 3: (2, 0), 4: (3, 1), 5: (4, 0)} # 绘制初始状态的网络图 nx.draw(G, pos, with_labels=True) plt.show() # 定义时序数据 time_data = {1: [(1, 4)], 2: [(2, 5)], 3: [(3, 1)], 4: [(4, 1)], 5: [(5, 2)], 6: [(1, 5), (3, 4)]} # 记录连通性 connected_components = [] # 按时间顺序更新网络 for t in sorted(time_data.keys()): # 更新边 for (u, v) in time_data[t]: G.add_edge(u, v) # 记录当前的连通性 connected_components.append(nx.strongly_connected_components(G)) # 绘制当前状态的网络图 nx.draw(G, pos, with_labels=True) # 绘制连通性变化 plt.title('Time Step: {}'.format(t)) plt.show() # 判断连通性是否发生变化 if len(connected_components[-1]) != len(connected_components[-2]): print('Connectivity Changed at Time Step:', t) ``` 这段代码创建了一个有向图,然后定义了时序数据,按时间顺序更新网络,并通过 Matplotlib 库绘制出现有的网络图和每个时间步的网络图。同时,记录每个时间步的连通性,并在连通性变化时输出提示信息。 这个例子中存在两个连通分量,分别是节点1、2、3和节点4、5。在第六个时间步,由于添加了两条跨越不同连通分量的边,导致网络连通性发生变化,输出了提示信息。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值