Skip to content

Commit

Permalink
Merge branch '1489' into ubuntu24
Browse files Browse the repository at this point in the history
  • Loading branch information
tigercosmos committed Jun 23, 2024
2 parents 8541ce1 + 2241be8 commit 84245b7
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 6 deletions.
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==6.0.0
16 changes: 14 additions & 2 deletions ci/run_tests/run_tests.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,22 @@
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()
parser.add_argument("--interface", type=str, required=True, help="interface to use")
Expand All @@ -32,7 +43,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
19 changes: 16 additions & 3 deletions ci/run_tests/run_tests_windows.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,27 @@
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):
print(interface)
addresses = psutil.net_if_addrs().get(interface)
print(addresses)
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(
["tcpreplay.exe", "--listnics"],
Expand All @@ -27,7 +40,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 Expand Up @@ -64,7 +77,7 @@ def main():

tcpreplay_interface, ip_address = find_interface()
if not tcpreplay_interface or not ip_address:
print("Cannot find an interface to run tests on!")
print("Cannot find an interface to run tests on! Info from psutil.net_if_addrs() %s"% psutil.net_if_addrs())
exit(1)
print(f"Interface is {tcpreplay_interface} and IP address is {ip_address}")

Expand Down

0 comments on commit 84245b7

Please sign in to comment.