Chinaunix首页 | 论坛 | 博客
  • 博客访问: 175956
  • 博文数量: 42
  • 博客积分: 315
  • 博客等级: 二等列兵
  • 技术积分: 461
  • 用 户 组: 普通用户
  • 注册时间: 2010-10-16 11:55
文章分类

全部博文(42)

文章存档

2013年(29)

2012年(7)

2011年(6)

我的朋友

分类: LINUX

2013-05-23 11:17:20

#-*-coding:utf-8-*-
import os
import sys
import urllib2
import pygame
import re
import socket
import subprocess

# 输入要测试的site值
print "Hello"
print pygame.ver
site=raw_input("Pls Input Your Site:")
req = urllib2.Request('')
fd = urllib2.urlopen(req)



#连接文件的第一列为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"  %   domain
else:
    print "Domain name resolution %s: is FAIL" %  domain
    
#ping 测试 电信IP不行,就测试联通IP   
dxping = 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" %  DXIP
else:
    print "ping DX %s is  FAIL"   % DXIP
if ltping == 0:
    print "ping LT %s: is OK" % LTIP
else:
    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.......")
阅读(4551) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~