[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))
|
||||
def __str__(self):
|
||||
return "%s\n status : %s\n %s" % (self.cmd,self.err_code,self.output)
|
||||
|
||||
|
||||
class Ipset(object):
|
||||
ipset="/usr/sbin/ipset"
|
||||
def __init__(self,set,type,typeopt=''):
|
||||
self.set=set
|
||||
self.type=type
|
||||
self.typeoption=typeopt
|
||||
|
||||
self.typeopt=typeopt
|
||||
|
||||
def call(self,cmd,arg=''):
|
||||
"""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))
|
||||
status,output=commands.getstatusoutput(cmd_line)
|
||||
if status:
|
||||
raise IpsetError(cmd_line,status,output)
|
||||
return output
|
||||
|
||||
|
||||
def create(self,opt=''):
|
||||
self.call("-N","%s %s" % (self.type, self.typeopt))
|
||||
|
||||
def add(self,arg):
|
||||
self.call("-A",arg)
|
||||
|
||||
|
||||
def list(self):
|
||||
output=self.call("-L").splitlines()
|
||||
list=[]
|
||||
|
@ -67,12 +67,15 @@ class Ipset(object):
|
|||
break
|
||||
list.append(line)
|
||||
return list
|
||||
|
||||
|
||||
def delete(self,ip):
|
||||
"""Delete an IP"""
|
||||
self.call("-D",ip)
|
||||
|
||||
|
||||
def flush(self):
|
||||
self.call("-F")
|
||||
|
||||
|
||||
|
||||
def destroy(self):
|
||||
self.call("-X")
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue