Use ipaddress module to store IP

This commit is contained in:
nemunaire 2014-12-31 07:54:05 +01:00
parent 0d4130b391
commit 116c81f5b2
3 changed files with 4 additions and 19 deletions

3
bot.py
View File

@ -18,6 +18,7 @@
from datetime import datetime, timedelta, timezone
import imp
import ipaddress
import logging
from queue import Queue
import re
@ -59,7 +60,7 @@ class Bot(threading.Thread):
self.verbosity = verbosity
# External IP for accessing this bot
self.ip = ip
self.ip = ipaddress.ip_address(ip)
# Context paths
self.modules_paths = modules_paths

View File

@ -18,6 +18,7 @@
import calendar
from datetime import datetime, timezone
import ipaddress
import re
import time
import shlex
@ -26,7 +27,6 @@ from channel import Channel
import message
from message.printer.IRC import IRC as IRCPrinter
from server.socket import SocketServer
import tools
class IRC(SocketServer):
@ -82,7 +82,7 @@ class IRC(SocketServer):
def _ctcp_dcc(msg, cmds):
"""Response to DCC CTCP message"""
try:
ip = tools.toIP(int(cmds[3]))
ip = ipaddress.ip_address(int(cmds[3]))
port = int(cmds[4])
conn = DCC(srv, msg.sender)
except:

View File

@ -19,22 +19,6 @@
import imp
def intToIP(n):
ip = ""
for i in range(0, 4):
mod = n % 256
ip = "%d.%s" % (mod, ip)
n = (n - mod) / 256
return ip[:len(ip) - 1]
def ipToInt(ip):
sum = 0
for b in ip.split("."):
sum = 256 * sum + int(b)
return sum
def reload():
import tools.countdown
imp.reload(tools.countdown)