Skip to content
This repository was archived by the owner on Oct 29, 2019. It is now read-only.

Commit 11b8af9

Browse files
committed
2 parents 731d8ca + 7761256 commit 11b8af9

2 files changed

Lines changed: 11 additions & 7 deletions

File tree

network/utils.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,15 @@
33
44
:author: Connor Henley @thatging3rkid
55
"""
6+
import fcntl
67
import socket
8+
import struct
79

8-
# shamelessly stolen from https://stackoverflow.com/a/1267524
9-
def get_ip():
10-
try:
11-
return [ip for ip in socket.gethostbyname_ex(socket.gethostname())[2] if not ip.startswith("127.")][:1][0]
12-
except:
13-
return "127.0.0.1"
10+
# shamelessly stolen from https://stackoverflow.com/a/24196955
11+
def get_ip(ifname):
12+
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
13+
return socket.inet_ntoa(fcntl.ioctl(
14+
s.fileno(),
15+
0x8915, # SIOCGIFADDR
16+
struct.pack('256s', bytes(ifname[:15], 'utf-8'))
17+
)[20:24])

utils/HeaderParser.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ def __parse(self, file):
9595

9696
# Skip the line if it should not be processed (ie #ifdef is false)
9797
if depth != -1:
98-
if not process_ln[depth] is None or process_ln[depth] is True:
98+
if not(process_ln[depth] == None or process_ln[depth] == True):
9999
continue
100100

101101
# See if the line starts with #define

0 commit comments

Comments
 (0)