码迷,mamicode.com
首页 > 其他好文 > 详细

网络编程 IP地址

时间:2015-05-08 14:27:06      阅读:93      评论:0      收藏:0      [点我收藏+]

标签:

import java.net.*;

public class IPDemo {

          public static void main(String[] args) throws Exception  

                {

                        InetAddress i=InetAddress.getLocalHost();  

                          /*                            * 输出本机的主机名和IP地址                            */

                        //System.out.println(i.toString());

                          /*                            * 输出本机IP地址                              */ 

                       //System.out.println("address:"+i.getHostAddress());

                          /*                            * 输出本机的主机名                            */

                       //System.out.println("name:"+i.getHostName());

                          /*                            * 任意主机IP地址                            */

                       InetAddress ia=InetAddress.getByName("192.168.3.125");   

                          /*                            * 输出该本机的IP地址                            */

                        System.out.println("address:"+i.getHostAddress()); 

                          /*                            * 输出该本机的主机名                            */

                       System.out.println("name:"+i.getHostName()); 

                 }

}

网络编程 IP地址

标签:

原文地址:http://www.cnblogs.com/binglin/p/4487403.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!