feat: enhance interface details display to include separate IPv6 column
This commit is contained in:
@ -160,12 +160,13 @@ def display_interface_details(show_physical=False, show_virtual=False, show_all=
|
|||||||
|
|
||||||
Notes:
|
Notes:
|
||||||
- By default, only IPv4 addresses are shown unless `-6` is specified.
|
- By default, only IPv4 addresses are shown unless `-6` is specified.
|
||||||
|
- IPv6 addresses are displayed in a separate column if `-6` is specified.
|
||||||
"""
|
"""
|
||||||
if show_external_ip:
|
if show_external_ip:
|
||||||
ipv4, ipv6 = get_external_ips()
|
ipv4, ipv6 = get_external_ips()
|
||||||
print(f"External IPv4: {ipv4}")
|
print(f"External IPv4: {ipv4}")
|
||||||
print(f"External IPv6: {ipv6}")
|
print(f"External IPv6: {ipv6}")
|
||||||
print("-" * 50)
|
print("-" * 70)
|
||||||
|
|
||||||
interfaces = []
|
interfaces = []
|
||||||
|
|
||||||
@ -185,15 +186,20 @@ def display_interface_details(show_physical=False, show_virtual=False, show_all=
|
|||||||
# Define column widths based on expected maximum content length
|
# Define column widths based on expected maximum content length
|
||||||
col_widths = {
|
col_widths = {
|
||||||
'interface': 15,
|
'interface': 15,
|
||||||
'ip': 18,
|
'ipv4': 18,
|
||||||
|
'ipv6': 40 if show_ipv6 else 0, # Hide IPv6 column if not showing IPv6
|
||||||
'subnet': 10,
|
'subnet': 10,
|
||||||
'state': 10,
|
'state': 10,
|
||||||
'mac': 18
|
'mac': 18
|
||||||
}
|
}
|
||||||
|
|
||||||
# Print header with proper formatting
|
# Print header with proper formatting
|
||||||
print(f"{'Interface':<{col_widths['interface']}} {'IP Address':<{col_widths['ip']}} {'Subnet':<{col_widths['subnet']}} {'State':<{col_widths['state']}} {'MAC Address':<{col_widths['mac']}}")
|
header = f"{'Interface':<{col_widths['interface']}} {'IPv4 Address':<{col_widths['ipv4']}}"
|
||||||
print("-" * (col_widths['interface'] + col_widths['ip'] + col_widths['subnet'] + col_widths['state'] + col_widths['mac']))
|
if show_ipv6:
|
||||||
|
header += f" {'IPv6 Address':<{col_widths['ipv6']}}"
|
||||||
|
header += f" {'Subnet':<{col_widths['subnet']}} {'State':<{col_widths['state']}} {'MAC Address':<{col_widths['mac']}}"
|
||||||
|
print(header)
|
||||||
|
print("-" * (col_widths['interface'] + col_widths['ipv4'] + (col_widths['ipv6'] if show_ipv6 else 0) + col_widths['subnet'] + col_widths['state'] + col_widths['mac']))
|
||||||
|
|
||||||
for interface in interfaces:
|
for interface in interfaces:
|
||||||
try:
|
try:
|
||||||
@ -202,25 +208,27 @@ def display_interface_details(show_physical=False, show_virtual=False, show_all=
|
|||||||
state, mac = get_interface_state(interface)
|
state, mac = get_interface_state(interface)
|
||||||
if result.returncode == 0:
|
if result.returncode == 0:
|
||||||
lines = result.stdout.strip().splitlines()
|
lines = result.stdout.strip().splitlines()
|
||||||
|
ipv4 = "N/A"
|
||||||
|
ipv6 = "N/A"
|
||||||
|
subnet = ""
|
||||||
|
|
||||||
for line in lines:
|
for line in lines:
|
||||||
parts = line.split()
|
parts = line.split()
|
||||||
if len(parts) >= 3:
|
if len(parts) >= 3:
|
||||||
name = parts[0]
|
|
||||||
ip_with_mask = parts[2]
|
ip_with_mask = parts[2]
|
||||||
|
|
||||||
# Skip IPv6 addresses unless `-6` is specified
|
# Check if the address is IPv4 or IPv6
|
||||||
if ":" in ip_with_mask and not show_ipv6:
|
if ":" in ip_with_mask: # IPv6
|
||||||
continue
|
ipv6 = ip_with_mask.split('/')[0]
|
||||||
|
else: # IPv4
|
||||||
|
ipv4 = ip_with_mask.split('/')[0]
|
||||||
|
subnet = ip_with_mask.split('/')[1] if '/' in ip_with_mask else ""
|
||||||
|
|
||||||
# Split IP/mask
|
row = f"{interface:<{col_widths['interface']}} {ipv4:<{col_widths['ipv4']}}"
|
||||||
if '/' in ip_with_mask:
|
if show_ipv6:
|
||||||
ip = ip_with_mask.split('/')[0]
|
row += f" {ipv6:<{col_widths['ipv6']}}"
|
||||||
subnet = ip_with_mask.split('/')[1]
|
row += f" {subnet:<{col_widths['subnet']}} {state:<{col_widths['state']}} {mac:<{col_widths['mac']}}"
|
||||||
else:
|
print(row)
|
||||||
ip = ip_with_mask
|
|
||||||
subnet = ""
|
|
||||||
|
|
||||||
print(f"{name:<{col_widths['interface']}} {ip:<{col_widths['ip']}} {subnet:<{col_widths['subnet']}} {state:<{col_widths['state']}} {mac:<{col_widths['mac']}}")
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"Error fetching details for {interface}: {e}")
|
print(f"Error fetching details for {interface}: {e}")
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user