I Googled but couldn't find any reference to anything which would specifically list what predictable interface names were in use or allow what they were to be easily identified. Best I could come up with was to take the output of 'ifconfig -a' and parse that with some Python.
I guess you could do something like that, determine what's most likely to be the interface name to use, stick it in a shell variable and use variable substitution in your bash script.
Code: Select all
#!/usr/bin/python
import os
def PrintInterfaceList():
lst = os.popen("ifconfig -a").read().split("\n")
for s in lst:
s = s.rstrip()
if not s.startswith(" "):
n = s.find(": ")
if n > 0 :
print s[:n]
if __name__ == "__main__":
PrintInterfaceList()
I believe this shows how a predictable name is determined -
https://github.com/systemd/systemd/blob ... n-net_id.c
That should help identify what an interface is from its name; eg starts with "en" for ethernet, and one can then determine if it's a USB interface or something else etc.
The Pi LAN chip may get a reasonably constant prefix across systems, and if there isn't a wired NIC then look for a USB NIC.
Things won't work well with more than one NIC, but it didn't work well with the older convention either when it couldn't be guaranteed which was eth0 or eth1.