How to get the LAN IP of a client using Java?

前端 未结 5 979
攒了一身酷
攒了一身酷 2021-02-06 09:22

How can i get the LAN IP-address of a computer using Java? I want the IP-address which is connected to the router and the rest of the network.

I\'ve tried something like

5条回答
  •  遇见更好的自我
    2021-02-06 09:23

    As Daniel already pointed out, you cannot know which interface is the one "connected". What if, for example, the computer has multiple network interface cards which are both connected to separate physical LANs?

    Let the user decide which interface to use or try them all, depending on what your use case is.

提交回复
热议问题