2
PC with onboard linux has several network interfaces, e.g. two ethernet cards and one wifi adapter (numbers and types may vary). Each of that interfaces could be connected to a network (and could be offline) and the network could be connected to internet(superuser.com site is reachable), and could be connected to local-only network.
I want to write a bash script to get (local) IP address and name of adapter that can be used to reach internet.
If several are connected - it should be the one that would be used by browser that is "asked" to load superuser.com web pages. If no connected script should echo "internet unavailble"
How to write a check condition for such script?
How could i even iterate all networking-capable devices under /dev/*
in a system?
1@KamilMaciorowski I think that you misread question. I asked for iteration method. I dont need routes and schemes, i want to know.. a wildcard for devices. i cannot put there /dev/eth* because interface could be named enp3s0 for example, or it could be wifi adapter or usb network adapter. – xakepp35 – 2018-10-17T09:49:28.490
Each paragraph in your question asks for a completely different thing. "How do I get the default interface name?" "Wait, no, I don't want the default interface, I want all the interfaces"... The (deleted) post did exactly what your question's 2nd paragraph requires. – user1686 – 2018-10-17T10:33:12.897
Is your basic question that you want a command that you can run locally that will inform you which interface will be routing traffic to the Internet? – Hogstrom – 2018-10-17T11:36:29.043
@xakepp35 a browser doesn't decide which network interface to use, the way packets go out is decided by the routing table – AnonymousLurker – 2018-10-17T13:15:17.357
@AnonymousLurker Sure thing. I wrote so for simplicity of wording. If you dont like "browser" i can replace it with a "ping" command or whatever. – xakepp35 – 2018-10-17T14:14:06.340