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

View File

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

View File

@ -19,22 +19,6 @@
import imp 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(): def reload():
import tools.countdown import tools.countdown
imp.reload(tools.countdown) imp.reload(tools.countdown)