Created
November 2, 2011 03:36
-
-
Save ri0day/1332789 to your computer and use it in GitHub Desktop.
checker_tcp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
import sys | |
import MySQLdb | |
import ConfigParser | |
config=ConfigParser.ConfigParser() | |
config.readfp(open('/tmp/DNS.conf')) | |
pick_list=config.get('DNS','ip') | |
hostlist=map(str,pick_list.split(',')) | |
def pingcmd(ip,port): | |
import socket | |
sk = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |
sk.settimeout(2) | |
try: | |
sk.connect((ip,port)) | |
yield 'succ' | |
except Exception: | |
print ip,port | |
sk.close() | |
ip_pool_swap=[] | |
for hosts in hostlist: | |
ip=hosts.split(':')[-2] | |
port=int(hosts.split(':')[-1]) | |
try: | |
ping_stats=pingcmd(ip,port) | |
except Exception,e: | |
print >> sys.stderr, "ping port error:",e | |
# sys.exit(1) | |
if next(ping_stats,'over') == 'succ': | |
isok=1 | |
ip_pool_swap.append(ip) | |
else: | |
print 'repilication ouch...%s %s'%(ip,port) | |
isok=0 | |
#UNIQ ip pool | |
ip_pool=list(set(ip_pool_swap)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment