Hello dear friends, I got to hand Masterserver for cs, interested in a couple of questions for him as I am in Python almost do not understand, the script displays a list of servers, but with a large number of servers starts to duplicate the connections as shown in the figure,

With more than 16 to the ip address script has denied:

I would like to increase the performance of the script and remove duplication in the list of servers, help or tell me.

The code:
Code:
#Masterserver v0.3 by Arsegg - 13.10.12
#(c) Arsegg, 2012
import socket,MySQLdb,ConfigParser,sqlite3,sys,thread,time

def serve_forever():
	host,port = cfg.get("OPTIONS","HOST"),cfg.getint("OPTIONS","PORT")
	s = socket.socket(socket.AF_INET,socket.SOCK_DGRAM)
	s.bind((host,port))
	while 1:
		data,addr = s.recvfrom(1024)
		s.sendto(d,addr)
		
		
def load_servers():
	mode = cfg.get("OPTIONS","MODE")
	if mode == "FILE":
		file = cfg.get("FILE","FILE")
		srv = [i.strip("\n") for i in open(file)]
	elif mode == "MYSQL":
		host,name,user,password,table = cfg.get("MYSQL","HOST"),cfg.get("MYSQL","NAME"),cfg.get("MYSQL","USER"),cfg.get("MYSQL","PASSWORD"),cfg.get("MYSQL","TABLE")
		db = MySQLdb.connect(host=host,user=user,passwd=password,db=name)
		c = db.cursor()
		c.execute("SELECT * FROM %s"%table)
		srv = [i[0] for i in c.fetchall()]
	elif mode == "SQLITE":
		name = cfg.get("SQLITE","FILE")
		db = sqlite3.connect(name)
		c = db.cursor()
		c.execute("SELECT * FROM %s"%table)
		srv = [i[0] for i in c.fetchall()]
	global d
	_d = [0xFF,0xFF,0xFF,0xFF,0x66,0x0A]
	for i in srv:
		ip,port = i.split(":")
		ip = [int(j) for j in ip.split(".")]
		port = int(port)
		port = [port>>8&0xFF,port&0xFF]
		map(_d.append,ip)
		map(_d.append,port)
	_d += [0x00,0x00,0x00,0x00,0x00,0x00]
	d = "".join([chr(i) for i in _d])
	
	print "Masterserver v0.2\n\nServer list:"
	for i in srv:
		print "\t",i
		
		
try:
	cfg = ConfigParser.ConfigParser()
	cfg.read("ms.cfg")
	refresh = cfg.getfloat("OPTIONS","REFRESH")

	load_servers()
	thread.start_new_thread(serve_forever,())
	while 1:
		time.sleep(refresh)
		print "\n"
		load_servers()
except:
	print sys.exc_info()[0]

Config file:
Code:
[OPTIONS]
HOST = 0.0.0.0
PORT = 27010
#MODE = FILE
MODE = MYSQL
#MODE = SQLITE
REFRESH = 10

[FILE]
FILE = servers.txt

[MYSQL]
HOST = 
NAME = 
USER = 
PASSWORD = 
TABLE = 

[SQLITE]
FILE = servers.db
I'm not a script writer and respected Arsegg for which he thanks.