twisted.names, c'est tout pourri
Oukaidi Oukaida darcs-hash:20050301190734-d1718-66f862145fe054385991816ddb5e754c858440ba.gz
This commit is contained in:
parent
d49a5e0ffb
commit
9ae7da34fe
1 changed files with 39 additions and 11 deletions
|
@ -37,13 +37,14 @@
|
||||||
|
|
||||||
# TODO: meilleure gestion des erreurs
|
# TODO: meilleure gestion des erreurs
|
||||||
|
|
||||||
|
import commands,re
|
||||||
|
|
||||||
# On utilise twisted
|
# On utilise twisted
|
||||||
# http://twistedmatrix.com/documents/current/howto/tutorial/intro
|
# http://twistedmatrix.com/documents/current/howto/tutorial/intro
|
||||||
from twisted.internet import protocol, reactor, defer, utils
|
from twisted.internet import protocol, reactor, defer, utils
|
||||||
from twisted.internet.ssl import ContextFactory
|
from twisted.internet.ssl import ContextFactory
|
||||||
from twisted.protocols import basic
|
from twisted.protocols import basic
|
||||||
from twisted.application import internet, service
|
from twisted.application import internet, service
|
||||||
from twisted.names import client
|
|
||||||
from twisted.python import log
|
from twisted.python import log
|
||||||
|
|
||||||
import sys, resource
|
import sys, resource
|
||||||
|
@ -143,10 +144,7 @@ class UpdateFactory(protocol.ServerFactory):
|
||||||
def reset_host(self, host):
|
def reset_host(self, host):
|
||||||
# ETAPE 1
|
# ETAPE 1
|
||||||
# On commence par résoudre "host".
|
# On commence par résoudre "host".
|
||||||
d = client.lookupPointer("%s.in-addr.arpa" % '.'.join(host.split('.')[::-1]))
|
return defer.succeed(reset_del(self, RE.get_reverse(host)))
|
||||||
d.addCallback(lambda (ans, auth, add), _ : reset_del(self, ans[0].payload.name),
|
|
||||||
lambda _: reset_del(self, "unknown"))
|
|
||||||
return d
|
|
||||||
|
|
||||||
def reset_del(self, host):
|
def reset_del(self, host):
|
||||||
# ETAPE 2
|
# ETAPE 2
|
||||||
|
@ -200,11 +198,7 @@ class UpdateFactory(protocol.ServerFactory):
|
||||||
def getSAD_host(self, getre, delre, host):
|
def getSAD_host(self, getre, delre, host):
|
||||||
# ETAPE 1
|
# ETAPE 1
|
||||||
# On commence par résoudre "host".
|
# On commence par résoudre "host".
|
||||||
d = client.lookupPointer("%s.in-addr.arpa" % '.'.join(host.split('.')[::-1]))
|
return getSAD_lock(self, getre, delre, RE.get_reverse(host))
|
||||||
d.addCallback(lambda (ans, auth, add), _ : getSAD_lock(self, getre, delre,
|
|
||||||
ans[0].payload.name),
|
|
||||||
lambda _: getSAD_lock(self, getre, delre, "unknown"))
|
|
||||||
return d
|
|
||||||
|
|
||||||
def getSAD_lock(self, getre, delre, host):
|
def getSAD_lock(self, getre, delre, host):
|
||||||
# ETAPE 2
|
# ETAPE 2
|
||||||
|
@ -263,7 +257,7 @@ class UpdateFactory(protocol.ServerFactory):
|
||||||
|
|
||||||
remove_lock('gen_confs.wifi')
|
remove_lock('gen_confs.wifi')
|
||||||
if len(result) > 5:
|
if len(result) > 5:
|
||||||
print "We send the following script :"
|
print "We send the following script to %s :" % host
|
||||||
print result
|
print result
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
@ -274,6 +268,40 @@ class UpdateFactory(protocol.ServerFactory):
|
||||||
|
|
||||||
# Corps du programme
|
# Corps du programme
|
||||||
|
|
||||||
|
class ReverseEngine:
|
||||||
|
|
||||||
|
import time
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
self.iphost = None
|
||||||
|
self.lastupdate = 0
|
||||||
|
|
||||||
|
def get_reverse(self,ip):
|
||||||
|
|
||||||
|
def build_reverse(server="138.231.136.6"):
|
||||||
|
"""Construit une correspondance IP -> nom"""
|
||||||
|
pattern = re.compile("^(.*).in-addr.arpa domain name pointer (.*)\.")
|
||||||
|
result = {}
|
||||||
|
for line in commands.getoutput("host -l 148.231.138.in-addr.arpa %s" % server).split("\n"):
|
||||||
|
mo = pattern.match(line.strip())
|
||||||
|
if mo:
|
||||||
|
ip = ".".join(mo.group(1).split(".")[::-1])
|
||||||
|
result[ip] = mo.group(2)
|
||||||
|
return result
|
||||||
|
|
||||||
|
current = time.time()
|
||||||
|
if not self.iphost or current - self.lastupdate > 60:
|
||||||
|
self.iphost = build_reverse()
|
||||||
|
self.lastupdate = current
|
||||||
|
|
||||||
|
if ip not in self.iphost:
|
||||||
|
return "unknown"
|
||||||
|
else:
|
||||||
|
return self.iphost[ip]
|
||||||
|
|
||||||
|
RE = ReverseEngine()
|
||||||
|
|
||||||
|
|
||||||
# On augmente la limite soft (qui semble arreter python).
|
# On augmente la limite soft (qui semble arreter python).
|
||||||
# Sous Open, on peut utiliser fstat pour voir les fichiers ouverts.
|
# Sous Open, on peut utiliser fstat pour voir les fichiers ouverts.
|
||||||
# On a besoin de 3 * nombre de bornes pour le nombre de descripteurs
|
# On a besoin de 3 * nombre de bornes pour le nombre de descripteurs
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue