美文网首页
Java日志记录获取本机IP地址

Java日志记录获取本机IP地址

作者: Miki_Zhang | 来源:发表于2018-11-19 10:15 被阅读6次

import java.net.InetAddress;

public class Main {  public static void main(String[] args)

  throws Exception {      InetAddress addr = InetAddress.getLocalHost();

      System.out.println("Local HostAddress:

      "+addr.getHostAddress());

      String hostname = addr.getHostName();

      System.out.println("Local host name: "+hostname);

  }}

以下为代码的输出结果:

Local HostAddress: 192.168.1.4

Local host name: harsh

相关文章

网友评论

      本文标题:Java日志记录获取本机IP地址

      本文链接:https://www.haomeiwen.com/subject/vfdofqtx.html