[ipset] ménage
darcs-hash:20110227125846-ffbb2-55a2463b21c469fdd04dea5c99beffd2cd64b897.gz
This commit is contained in:
parent
c08b4c80ce
commit
26ca045510
1 changed files with 13 additions and 10 deletions
|
@ -36,29 +36,29 @@ class IpsetError(Exception):
|
||||||
syslog.syslog(syslog.LOG_ERR,"%s : status %s,%s" % (cmd,err_code,output))
|
syslog.syslog(syslog.LOG_ERR,"%s : status %s,%s" % (cmd,err_code,output))
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return "%s\n status : %s\n %s" % (self.cmd,self.err_code,self.output)
|
return "%s\n status : %s\n %s" % (self.cmd,self.err_code,self.output)
|
||||||
|
|
||||||
class Ipset(object):
|
class Ipset(object):
|
||||||
ipset="/usr/sbin/ipset"
|
ipset="/usr/sbin/ipset"
|
||||||
def __init__(self,set,type,typeopt=''):
|
def __init__(self,set,type,typeopt=''):
|
||||||
self.set=set
|
self.set=set
|
||||||
self.type=type
|
self.type=type
|
||||||
self.typeoption=typeopt
|
self.typeopt=typeopt
|
||||||
|
|
||||||
def call(self,cmd,arg=''):
|
def call(self,cmd,arg=''):
|
||||||
"""Appel système à ipset"""
|
"""Appel système à ipset"""
|
||||||
cmd_line="%s %s %s %s" % (ipset,cmd,self.set,arg)
|
cmd_line="%s %s %s %s" % (self.ipset,cmd,self.set,arg)
|
||||||
syslog.syslog(syslog.LOG_INFO,"ipset: %s, %s" % (self.set,arg))
|
syslog.syslog(syslog.LOG_INFO,"ipset: %s, %s" % (self.set,arg))
|
||||||
status,output=commands.getstatusoutput(cmd_line)
|
status,output=commands.getstatusoutput(cmd_line)
|
||||||
if status:
|
if status:
|
||||||
raise IpsetError(cmd_line,status,output)
|
raise IpsetError(cmd_line,status,output)
|
||||||
return output
|
return output
|
||||||
|
|
||||||
def create(self,opt=''):
|
def create(self,opt=''):
|
||||||
self.call("-N","%s %s" % (self.type, self.typeopt))
|
self.call("-N","%s %s" % (self.type, self.typeopt))
|
||||||
|
|
||||||
def add(self,arg):
|
def add(self,arg):
|
||||||
self.call("-A",arg)
|
self.call("-A",arg)
|
||||||
|
|
||||||
def list(self):
|
def list(self):
|
||||||
output=self.call("-L").splitlines()
|
output=self.call("-L").splitlines()
|
||||||
list=[]
|
list=[]
|
||||||
|
@ -67,12 +67,15 @@ class Ipset(object):
|
||||||
break
|
break
|
||||||
list.append(line)
|
list.append(line)
|
||||||
return list
|
return list
|
||||||
|
|
||||||
def delete(self,ip):
|
def delete(self,ip):
|
||||||
"""Delete an IP"""
|
"""Delete an IP"""
|
||||||
self.call("-D",ip)
|
self.call("-D",ip)
|
||||||
|
|
||||||
def flush(self):
|
def flush(self):
|
||||||
self.call("-F")
|
self.call("-F")
|
||||||
|
|
||||||
|
def destroy(self):
|
||||||
|
self.call("-X")
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue