I need to find the adapter name and default gateway for the ethernet adapter used to connect to the internet.
I can get the gateway with netstat -rn
but I'm having problem with the adapter name.
I'm using java and running a ipconfig
command for Windows systems and parsing the result. It returns the network adapter names in this format
Ethernet adapter Local Area Connection: Connection-specific DNS Suffix . : customer.service.provider.lan Link-local IPv6 Address . . . . . : fb80::7d2b:98aa:506:685%10 IPv4 Address. . . . . . . . . . . : 10.65.2.21 Subnet Mask . . . . . . . . . . . : 255.255.192.0 Default Gateway . . . . . . . . . : 10.65.0.1
I can match the default gateway and like to parse the string "Local Area Connection" for it. On English locale, I can look for the word "adapter" and parse the name until ":". Problem is on computers with different locale than English, "adapter" is called something else. How can I reliably obtain the network adapter name?