2
0
mirror of https://github.com/flotwig/spoofident synced 2025-08-30 13:58:16 +00:00

Switch to non-blocking select()

This commit is contained in:
root 2014-06-16 16:29:04 -04:00
parent 47e6982a3d
commit af254e5a78

View File

@ -1,6 +1,7 @@
from os import setuid,setgid,path from os import setuid,setgid,path
from json import load from json import load
import dualstack import socket
import select
def handleIdent(fd): def handleIdent(fd):
data=fd.recv(1024).strip() data=fd.recv(1024).strip()
ports=data.split(',',2) ports=data.split(',',2)
@ -25,9 +26,20 @@ if __name__ == '__main__':
config=open(pwd+'/spoofident.json','r') config=open(pwd+'/spoofident.json','r')
settings=load(config) settings=load(config)
config.close() config.close()
server = dualstack.MultipleSocketsListener(settings['listeners']) servers=[]
for pair in settings['listeners']:
if ':' in pair[0]: # TODO: write actual ip6 detection, properly?
servers.append(socket.socket(socket.AF_INET6,socket.SOCK_STREAM))
else:
servers.append(socket.socket(socket.AF_INET,socket.SOCK_STREAM))
print(str(pair[0])+'and'+str(pair[1]))
servers[-1].bind((pair[0], pair[1]))
servers[-1].listen(5)
servers[-1].setblocking(0)
setgid(settings['setgid']) setgid(settings['setgid'])
setuid(settings['setuid']) setuid(settings['setuid'])
while True: while True:
conn,addr=server.accept() inready,outready,excready=select.select(servers,[],[])
handleIdent(conn) for ready in inready:
client,addr=ready.accept()
handleIdent(client)