Пример #1
0
	def __init__(self, name, val):
		__pychecker__ = 'no-argsused'
		pos = val.find('/')
		if val[0] == '/' or val[-1] == '/':
			# very funny: -10 points.
			raise BadArg, "bad position of / in dnsbl: argument"
		if pos >= 0:
			self.dnsbl = "." + val[:pos]
			self.ipval = val[pos+1:]
			if not util.isipaddr(self.ipval):
				raise BadArg, "dnsbl: IP address portion isn't an IP address"
		else:
			self.dnsbl = "." + val
			self.ipval = None
Пример #2
0
def getipname(ip):
    try:
        revname = socket.gethostbyaddr(ip)[0]
    except socket.error:
        return ("unknown", None)
        # We have to do this explicitly, because gethostbyname_ex() will
        # work on IP addresses.
    if util.isipaddr(revname):
        return ("noforward", revname)
    try:
        ips = socket.gethostbyname_ex(revname)[2]
    except socket.error:
        return ("noforward", revname)
    for i in ips:
        if i == ip:
            return ("good", revname)
    return ("addrmismatch", revname)
Пример #3
0
	def testIsIpAddr(self):
		"""Test that known input produces the correct result from isipaddr."""
		for i, j in self.knownValues:
			self.assertEqual(util.isipaddr(i), j, "bad result at "+i)