2016-01-26 12:04:06 +01:00
|
|
|
import socket
|
2013-06-23 21:52:39 +02:00
|
|
|
import sys
|
2013-06-21 11:10:13 +02:00
|
|
|
|
2016-01-26 12:04:06 +01:00
|
|
|
import shared
|
|
|
|
|
2013-06-21 11:10:13 +02:00
|
|
|
def convertIntToString(n):
|
|
|
|
a = __builtins__.hex(n)
|
|
|
|
if a[-1:] == 'L':
|
|
|
|
a = a[:-1]
|
|
|
|
if (len(a) % 2) == 0:
|
|
|
|
return a[2:].decode('hex')
|
|
|
|
else:
|
|
|
|
return ('0' + a[2:]).decode('hex')
|
|
|
|
|
|
|
|
|
|
|
|
def convertStringToInt(s):
|
|
|
|
return int(s.encode('hex'), 16)
|
|
|
|
|
|
|
|
|
|
|
|
def signal_handler(signal, frame):
|
|
|
|
if shared.safeConfigGetBoolean('bitmessagesettings', 'daemon'):
|
|
|
|
shared.doCleanShutdown()
|
|
|
|
sys.exit(0)
|
|
|
|
else:
|
|
|
|
print 'Unfortunately you cannot use Ctrl+C when running the UI because the UI captures the signal.'
|
|
|
|
|
|
|
|
def isHostInPrivateIPRange(host):
|
2016-01-26 12:04:06 +01:00
|
|
|
if ":" in host: #IPv6
|
|
|
|
hostAddr = socket.inet_pton(socket.AF_INET6, host)
|
|
|
|
if hostAddr == ('\x00' * 15) + '\x01':
|
|
|
|
return False
|
|
|
|
if hostAddr[0] == '\xFE' and (ord(hostAddr[1]) & 0xc0) == 0x80:
|
|
|
|
return False
|
|
|
|
if (ord(hostAddr[0]) & 0xfe) == 0xfc:
|
|
|
|
return False
|
|
|
|
pass
|
|
|
|
else:
|
|
|
|
if host[:3] == '10.':
|
|
|
|
return True
|
|
|
|
if host[:4] == '172.':
|
|
|
|
if host[6] == '.':
|
|
|
|
if int(host[4:6]) >= 16 and int(host[4:6]) <= 31:
|
|
|
|
return True
|
|
|
|
if host[:8] == '192.168.':
|
|
|
|
return True
|
2013-06-21 11:10:13 +02:00
|
|
|
return False
|
2014-05-02 16:46:36 +02:00
|
|
|
|
2014-05-02 18:47:50 +02:00
|
|
|
def addDataPadding(data, desiredMsgLength = 12, paddingChar = '\x00'):
|
|
|
|
return data + paddingChar * (desiredMsgLength - len(data))
|