获得本机IP

来源:互联网 发布:徐水区网络平台 编辑:程序博客网 时间:2024/04/30 14:10

//java实现获得本机IP

/*
 * Main.java
 *
 * Created on 2007年6月6日, 下午11:09
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package getlocalhost;

/**
 *
 * @author Administrator
 */
public class Main {
   
    /** Creates a new instance of Main */
    public Main() {
    }
   
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        java.net.InetAddress myIp=null;
        try
        {
            myIp=java.net.InetAddress.getLocalHost();
        }
        catch(java.net.UnknownHostException e)
        {
        }
        System.out.println(myIp);
        }
        // TODO code application logic here
    }
   

 

原创粉丝点击