How do I get the local hostname if unresolvable through DNS in Java?

后端 未结 8 2452
清酒与你
清酒与你 2021-02-19 04:38

This sounds like something that should have been asked before, and it has sort of, but I\'m looking to get the local hostname and IP addresses of a machine even when it is not r

8条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-02-19 05:10

    This is a bit of a hack. But you could launch a new Process from Java and run the hostname command. Reading the outputstream of the child process would give you the name of the localhost.

提交回复
热议问题