diff --git a/bot.py b/bot.py index f99344c..1f74b8d 100644 --- a/bot.py +++ b/bot.py @@ -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 diff --git a/server/IRC.py b/server/IRC.py index bbe6334..ae01a74 100644 --- a/server/IRC.py +++ b/server/IRC.py @@ -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: diff --git a/tools/__init__.py b/tools/__init__.py index d2004b5..036b9ad 100644 --- a/tools/__init__.py +++ b/tools/__init__.py @@ -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)