#!/bin/bash

# Try to find the USB Ethernet interface first
iface=$(ip -o link | awk -F': ' '/enx|enp.*u/{print $2}' | head -n 1)

# If no USB interface, fall back to eth0
if [ -z "$iface" ]; then
	if ip link show eth0 &>/dev/null; then
		iface="eth0"
		echo "USB Ethernet not found. Using eth0."
	else
		echo "No suitable interface found."
		exit 1
	fi
else
	echo "Using USB Ethernet interface: $iface"
fi

# Assign IP address (only for USB interface, skip eth0)
# if [[ $iface != "eth0" ]]; then
	sudo ip addr add 192.168.192.10/24 dev "$iface" 2>/dev/null
# fi

# Bring interface up
sudo ip link set "$iface" up

# Scan port 9100 on the printer IP
nmap -p 9100 192.168.192.168

