Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace netifaces by scapy #1489

Merged
merged 16 commits into from
Aug 14, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ci/run_tests/requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
netifaces==0.11.0
psutil==5.9.8
14 changes: 12 additions & 2 deletions ci/run_tests/run_tests.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
import os
import subprocess
import argparse
import netifaces as ni
import psutil
import socket

PCAP_FILE_PATH = os.path.join("Tests", "Pcap++Test", "PcapExamples", "example.pcap")

def get_ip_address(interface):
addresses = psutil.net_if_addrs().get(interface)
if not addresses:
return None
for address in addresses:
if address.family == socket.AF_INET:
return address.address
return None

def main():
parser = argparse.ArgumentParser()
Expand Down Expand Up @@ -32,7 +41,8 @@ def main():
)
args = parser.parse_args()

ip_address = ni.ifaddresses(args.interface)[ni.AF_INET][0]["addr"]
ip_address = get_ip_address(args.interface)

print("IP address is: %s" % ip_address)

try:
Expand Down
13 changes: 11 additions & 2 deletions ci/run_tests/run_tests_windows.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
import os
import argparse
import subprocess
import netifaces as ni
import psutil
import socket

TCPREPLAY_PATH = "tcpreplay-4.4.1-win"
PCAP_FILE_PATH = os.path.abspath(
os.path.join("Tests", "Pcap++Test", "PcapExamples", "example.pcap")
)

def get_ip_address(interface):
addresses = psutil.net_if_addrs().get(interface)
if not addresses:
return None
for address in addresses:
if address.family == socket.AF_INET:
return address.address
return None

def find_interface():
completed_process = subprocess.run(
Expand All @@ -27,7 +36,7 @@ def find_interface():
interface = columns[1]
try:
ni_interface = interface.lstrip("\\Device\\NPF_")
ip_address = ni.ifaddresses(ni_interface)[ni.AF_INET][0]["addr"]
ip_address = get_ip_address(ni_interface)
if ip_address.startswith("169.254"):
continue
completed_process = subprocess.run(
Expand Down
Loading