mirror of
https://github.com/flotwig/spoofident
synced 2025-08-29 05:17:39 +00:00
Code cleanup
This commit is contained in:
parent
5f94526fc4
commit
86315bbb74
@ -4,23 +4,18 @@ from time import time
|
|||||||
from select import select
|
from select import select
|
||||||
import socket
|
import socket
|
||||||
def handleIdent(fd):
|
def handleIdent(fd):
|
||||||
begin=time()
|
fd.settimeout(1)
|
||||||
fd.setblocking(0)
|
|
||||||
data=''
|
|
||||||
while time()-begin<1:
|
|
||||||
try:
|
try:
|
||||||
data=fd.recv(1024).strip()
|
data=fd.recv(1024).strip()
|
||||||
if data: break
|
|
||||||
except:
|
except:
|
||||||
pass # TODO: catch exceptions which are actual errors, as opposed to no-data reports
|
fd.send('0,0:ERROR:UNKNOWN-ERROR\r\n') # TODO: catch exceptions which are actual errors, as opposed to no-data reports
|
||||||
|
return
|
||||||
ports=data.split(',',2)
|
ports=data.split(',',2)
|
||||||
ports=map(validPort,ports)
|
ports=map(validPort,ports)
|
||||||
if not data:
|
if len(ports)<2 or not all(ports):
|
||||||
fd.send('0,0:ERROR:UNKNOWN-ERROR\r\n')
|
|
||||||
elif len(ports)<2 or (not ports[0] or not ports[1]):
|
|
||||||
fd.send('0,0:ERROR:INVALID-PORT\r\n')
|
fd.send('0,0:ERROR:INVALID-PORT\r\n')
|
||||||
else:
|
else:
|
||||||
fd.send(str(ports[0])+','+str(ports[1])+':USERID:'+settings['os']+':'+settings['user']+'\r\n')
|
fd.send(','.join(map(str,ports))+':USERID:'+settings['os']+':'+settings['user']+'\r\n')
|
||||||
fd.close()
|
fd.close()
|
||||||
def validPort(port):
|
def validPort(port):
|
||||||
try:
|
try:
|
||||||
@ -29,26 +24,25 @@ def validPort(port):
|
|||||||
return False
|
return False
|
||||||
if port>0 and port<65536:
|
if port>0 and port<65536:
|
||||||
return port
|
return port
|
||||||
else:
|
|
||||||
return False
|
return False
|
||||||
if __name__ == '__main__':
|
if __name__=='__main__':
|
||||||
pwd=path.dirname(path.realpath(__file__))
|
pwd=path.dirname(path.realpath(__file__))
|
||||||
config=open(pwd+'/spoofident.json','r')
|
config=open(pwd+'/spoofident.json','r')
|
||||||
settings=load(config)
|
settings=load(config)
|
||||||
config.close()
|
config.close()
|
||||||
servers=[]
|
servers=[]
|
||||||
for pair in settings['listeners']:
|
for host,port in settings['listeners']:
|
||||||
if ':' in pair[0]: # TODO: write actual ip6 detection, properly?
|
if ':' in host: # TODO: write actual ip6 detection, properly?
|
||||||
servers.append(socket.socket(socket.AF_INET6,socket.SOCK_STREAM))
|
servers.append(socket.socket(socket.AF_INET6,socket.SOCK_STREAM))
|
||||||
else:
|
else:
|
||||||
servers.append(socket.socket(socket.AF_INET,socket.SOCK_STREAM))
|
servers.append(socket.socket(socket.AF_INET,socket.SOCK_STREAM))
|
||||||
servers[-1].bind((pair[0], pair[1]))
|
servers[-1].bind((host,port))
|
||||||
servers[-1].listen(5)
|
servers[-1].listen(5)
|
||||||
servers[-1].setblocking(0)
|
servers[-1].setblocking(0)
|
||||||
setgid(settings['setgid'])
|
setgid(settings['setgid'])
|
||||||
setuid(settings['setuid'])
|
setuid(settings['setuid'])
|
||||||
while True:
|
while True:
|
||||||
inready,outready,excready=select(servers,[],[])
|
inready,_,_=select(servers,[],[])
|
||||||
for ready in inready:
|
for ready in inready:
|
||||||
if ready in servers:
|
if ready in servers:
|
||||||
client,addr=ready.accept()
|
client,addr=ready.accept()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user