Use ipaddress module to store IP
This commit is contained in:
parent
0d4130b391
commit
116c81f5b2
3
bot.py
3
bot.py
@ -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
|
||||||
|
@ -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:
|
||||||
|
@ -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)
|
||||||
|
Loading…
Reference in New Issue
Block a user