| 61 | print 'Unfortunately you cannot use Ctrl+C when running the UI because the UI captures the signal.' |
| 62 | |
| 63 | def isHostInPrivateIPRange(host): |
| 64 | if ":" in host: #IPv6 |
| 65 | hostAddr = socket.inet_pton(socket.AF_INET6, host) |
| 66 | if hostAddr == ('\x00' * 15) + '\x01': |
| 67 | return False |
| 68 | if hostAddr[0] == '\xFE' and (ord(hostAddr[1]) & 0xc0) == 0x80: |
| 69 | return False |
| 70 | if (ord(hostAddr[0]) & 0xfe) == 0xfc: |
| 71 | return False |
| 72 | pass |
| 73 | elif ".onion" not in host: |
| 74 | if host[:3] == '10.': |
| 75 | return True |
| 76 | if host[:4] == '172.': |
| 77 | if host[6] == '.': |
| 78 | if int(host[4:6]) >= 16 and int(host[4:6]) <= 31: |
| 79 | return True |
| 80 | if host[:8] == '192.168.': |
| 81 | return True |
| 82 | # Multicast |
| 83 | if host[:3] >= 224 and host[:3] <= 239 and host[4] == '.': |
| 84 | return True |
| 85 | return False |
| 86 | |
| 87 | def addDataPadding(data, desiredMsgLength = 12, paddingChar = '\x00'): |
| 88 | return data + paddingChar * (desiredMsgLength - len(data)) |