Skip to content

Commit

Permalink
Problem: KeyError occurs from netifaces
Browse files Browse the repository at this point in the history
avoid network interfaces that doesn't have address info for netifaces.AF_INET
  • Loading branch information
mmsqe committed Jun 21, 2024
1 parent 903b590 commit 5f1014e
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions testground/benchmark/benchmark/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ def get_data_ip(params: RunParams) -> ipaddress.IPv4Address:
def ip4_addresses() -> List[ipaddress.IPv4Address]:
ip_list = []
for interface in netifaces.interfaces():
for link in netifaces.ifaddresses(interface)[netifaces.AF_INET]:
ip_list.append(ipaddress.IPv4Address(link["addr"]))
if netifaces.AF_INET in netifaces.ifaddresses(interface):
for link in netifaces.ifaddresses(interface)[netifaces.AF_INET]:
ip_list.append(ipaddress.IPv4Address(link["addr"]))
return ip_list

0 comments on commit 5f1014e

Please sign in to comment.