java ip地址相关操作
来源:互联网 发布:js 去除disabled 编辑:程序博客网 时间:2024/06/05 11:56
java ip地址相关操作
@(JAVA)[scala]
参考CORE JAVA。
在JAVA中,InetAddress类用于操作与IP地址相关的内容,常用方法如下:
java.net.InetAddress 1.0• static InetAddress getByName(String host)• static InetAddress[] getAllByName(String host)constructs an InetAddress, or an array of all Internetaddresses, for the given host name.• static InetAddress getLocalHost()constructs an InetAddress for the local host.• byte[] getAddress()returns an array of bytes that contains thenumerical address.• String getHostAddress()returns a string with decimal numbers,separated by periods, for example "132.163.4.102".• String getHostName()returns the host name.
一个例子:
package com.lujinhong.corejava;import java.net.InetAddress;import java.net.UnknownHostException;public class InetAddressTest { public static void main(String[] args) { try { // Get the first argument as the hostname. if (args.length > 0) { InetAddress[] inetAddresses = InetAddress.getAllByName(args[0]); for(InetAddress ia : inetAddresses){ System.out.println(ia); } }else{ //if No argument, get the localhost ip address. InetAddress localHostAddress = InetAddress.getLocalHost(); System.out.println(localHostAddress); System.out.println(localHostAddress); } } catch (UnknownHostException e) { e.printStackTrace(); } }}
阅读全文
0 0
- java ip地址相关操作
- java ip地址相关操作
- IP地址相关操作
- IP地址及相关操作运算
- java线程操作,IP地址接口
- java获取公网ip地址操作
- Ubuntu自动获取IP地址的相关操作/方法
- awk相关操作(简单举例查询IP地址)
- IP地址相关知识
- IP地址相关知识
- 8.IP地址相关
- Ip地址操作
- IP地址的相关知识
- QQ IP 地址查询相关
- IP地址相关知识整理
- IP地址之计算 相关
- IP地址、子网掩码相关计算
- IP地址、子网掩码相关知识
- Pycharm新建模板默认添加个人信息
- 为什么多线程线程处理数据经常出现singnal异常,寻址异常
- aspectj通知
- C# 设置图片透明度源码,支持16/24/32位色深
- 移动的上下左右滑动
- java ip地址相关操作
- Ubuntu下编译C程序的详解
- javascript学习(十四)— 面向对象编程
- php文件操作技巧FileSystem
- jessite 三
- OGG安装及进程理解
- Xamarin.Forms 用户界面——动画
- 170808 逆向-RouterScan(9)
- js随笔