获取本机的IP地址(Windows和Linux兼容)
来源:互联网 发布:知字取名 编辑:程序博客网 时间:2024/06/06 05:02
package com.cxg.demo.test;import java.net.Inet4Address;import java.net.InetAddress;import java.net.InterfaceAddress;import java.net.NetworkInterface;import java.net.SocketException;import java.util.ArrayList;import java.util.Enumeration;import java.util.List;/** * Title: 测试获取本机的IP测试类 * Description: TestDemo * @author: xg.chen * @date:2016年11月14日 下午4:07:00 */public class GetLocalhostIP { /** * MethodsTitle: 测试模块 * @author: xg.chen * @date:2016年11月14日 下午5:03:48 * @version 1.0 * @param args */ public static void main(String[] args) { getLoalhostIP(); } /** * MethodsTitle: 获取本机的IP * @author: xg.chen * @date:2016年11月14日 下午5:03:41 * @version 1.0 */ public static void getLoalhostIP(){ try { Enumeration<?> enumeration=NetworkInterface.getNetworkInterfaces(); InetAddress ip=null; while(enumeration.hasMoreElements()){ NetworkInterface netInterface = (NetworkInterface) enumeration.nextElement(); Enumeration<?> addresses = netInterface.getInetAddresses(); while (addresses.hasMoreElements()) { ip = (InetAddress) addresses.nextElement(); System.out.println("服务地址:" + ip.getHostName()); if (ip != null && ip instanceof Inet4Address){ String ip1=ip.getHostAddress(); System.out.println("本机所有的IP地址:"+ip1); } } } } catch (SocketException e) { e.printStackTrace(); } }}
0 0
- 获取本机的IP地址(Windows和Linux兼容)
- 获取本机ip地址(适用于linux、windows)
- Windows获取本机机器名和ip地址及ip地址的字符串形式
- linux下 获取本机ip地址和掩码地址
- linux下 获取本机ip地址和掩码地址
- vbscript获取本机的ip地址和mac地址
- java获取本机的IP地址和mac地址
- Qt 获取本机的IP地址和Mac地址
- 获取本机的IP地址和Mac地址
- windows平台获取本机IP地址
- Windows phone8 获取本机ip地址
- Windows phone8 获取本机 IP 地址
- Java获取本机IP地址(对外的IP地址和局域网的IP地址)
- linux下获取本机ip地址,ipv4和ipv6
- linux下获取本机ip地址,ipv4和ipv6
- linux中获取本机ip和mac地址
- Linux 获取本机IP地址和MAC地址(一)
- Linux 获取本机IP地址和MAC地址(二)
- LeetCode笔记:111. Minimum Depth of Binary Tree
- Python sys.argv[]
- [绍棠] 通过主屏幕的应用Icon,用3D Touch呼出一个菜单 (Home Screen Quick Actions)
- Hadoop 第一课 了解hadoop
- 实习第一周(第二天)(上午)(linux文件拥有者知识)
- 获取本机的IP地址(Windows和Linux兼容)
- 一维树状数组模板【pascal】
- VUE 菜单 +感想
- C#中常用的WebRequest方法
- 手机端的多图片剪辑上传支持手势支持预览
- Ext 主要控件
- 单片机json程序
- 分享个MesaSQLite 注册码
- 电脑慢简单有效三技巧