Skip to content

Commit

Permalink
Replace scapy with system commands
Browse files Browse the repository at this point in the history
  • Loading branch information
guyavrhm committed Jun 19, 2021
1 parent 289bcd2 commit c324275
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
PyQt5
numpy
scapy
pynput
21 changes: 19 additions & 2 deletions src/info/computerinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
"""

from sys import platform
from scapy.all import get_if_addr, conf
import subprocess
import re

Expand Down Expand Up @@ -49,4 +48,22 @@ def get_ip():
"""
Returns local IP of computer.
"""
return get_if_addr(conf.iface)
if platform == WINDOWS:
output = subprocess.check_output('ipconfig', shell=True).decode().split('\r\n')
ips = [output[i - 2].split(': ')[-1] for i, n in enumerate(output) if 'Default Gateway' in n if n[-1].isdigit()]

elif platform == LINUX:
output = subprocess.check_output('ip addr', shell=True).decode().split(' ')
ips = [n.split()[1].split("/")[0] for n in output if 'inet ' in n]

elif platform == MACOS:
output = subprocess.check_output('ifconfig', shell=True).decode().split('\t')
ips = [n.split()[1] for n in output if 'inet ' in n]

else:
return None

if len(ips) == 0:
return 'Not Found'
else:
return ips[-1]

0 comments on commit c324275

Please sign in to comment.