1

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?

siamii
  • 23,374
  • 28
  • 93
  • 143
  • 1
    I've also tried the API call `NetworkInterface.getName()`, but that returns "eth0" instead of the adapter name – siamii Dec 24 '11 at 21:10

1 Answers1

1

Take a look at this tutorial: Listing Network Interface Addresses And use getDisplayName() instand of getName(). See Heer to get the Gateway: How can I determine the IP of my router/gateway in Java?

Community
  • 1
  • 1
Thor
  • 6,607
  • 13
  • 62
  • 96
  • Tried. getDisplayName() returns the description of the adapter, which is model-make. Not the name. – siamii Dec 24 '11 at 22:42
  • actually, according to the tutorial, it should return the adapter name, but on my machine it doesn't. strange. – siamii Dec 24 '11 at 23:17