Java——IP和InetAddress】的更多相关文章

import java.net.InetAddress; //================================================= // File Name : InetAddress_demo //------------------------------------------------------------------------------ // Author : Common //主类 //Function : InetAddress_demo pu…
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 8…
IP地址 IP地址:InetAddress(没有构造器,通过静态方法返回) java.net包下 唯一定位一台网络上的计算机 127.0.0.1:本机localhost ip地址的分类 IPV4/IPV6 IPV4:192.168.194.1 32位 IPV6: 2409:8a55:227a:83c0:d028:ff84:6d2c:dee8 128位 公网(互联网)/私网(局域网) ABCD类地址 192.168.xx.xx专门给组织内部使用 域名: ping ip/域名 ipconfig 测试…
JAVA IP地址转成长整型方法 代码例如以下: /** * IP转成整型 * @param ip * @return */ public static Long ip2int(String ip) { Long num = 0L; if (ip == null){ return num; } try{ ip = ip.replaceAll("[^0-9\\.]", ""); //去除字符串前的空字符 String[] ips = ip.split("\\…
使用 InetAddress 获取 IP 地址会得到一个 byte 数组 如果你直接输出这个数组,你会发现 IP 地址中的某些位变成了负数 比如 61.135.169.105 会输出成 61.-121.-87.105 仔细看一看,会发现 135 + 121 = 256,169 + 87 = 256 -_-! 怎么个情况! 我首先想到的是 byte 类型向 int 类型转换过程中出现了问题,后来发现,实际不然 因为 Java 中没有 unsigned 类型,所以byte.short.int.lon…
在java.net包描述中, 简要说明了一些关键的接口. 其中负责networking identifiers的是Addresses. 这个类的具体实现类是InetAddress, 底层封装了Inet4Address与Inet6Address的异同, 可以看成一个Facade工具类. A Low Level API, which deals with the following abstractions: Addresses, which are networking identifiers,…
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.lang.reflect.Field; import java.lang.reflect.Method; import java.net.HttpURLConnection; import java.net.InetAddress;…
InetAddress用来代表IP地址.一个InetAdress的对象就代表着一个IP地址, getByName(String host):在给定主机名的情况下确定主机的 IP 地址,主机名可以是机器名(如 "java.sun.com"),也可以是其 IP 地址的文本表示形式.如果提供字面值 IP 地址,则仅检查地址格式的有效性 getHostName(): 获取此 IP 地址的主机名 getHostAddress():返回 IP 地址字符串(以文本表现形式) getLocalHost…
================================ ©Copyright 蕃薯耀 2020-01-17 https://www.cnblogs.com/fanshuyao/ import java.net.Inet4Address; import java.net.InetAddress; import java.net.NetworkInterface; import java.util.Enumeration; import javax.servlet.http.HttpSer…
package com.awkj; import java.math.BigInteger; import java.net.InetAddress; import java.net.UnknownHostException; public class App { private static BigInteger MIN_IP = new BigInteger("0"); private static BigInteger MAX_IP = new BigInteger("…
关于设置IP白名单相关的一些方法,整理,记录了一下. package com.tools.iptool; import java.util.ArrayList; import java.util.HashSet; import java.util.List; import java.util.Set; import java.util.regex.Pattern; /** * @ClassName:IPWhiteList * @Function: IP 白名单. * @Reason:关于IP白名…
早上一来,项目经理就说需要添加一个用户ip归属地查询功能,然后在网上搜罗半天,研究出一个比较简单的方法,通过接口返回地址json数据 有百度接口,新浪接口,这里用的是淘宝ip接口 通过淘宝IP地址库获取IP位置 请求接口(GET):http://ip.taobao.com/service/getIpInfo.php?ip=[ip地址字串] 响应信息:(json格式的)国家 .省(自治区或直辖市).市(县).运营商等 2018.2.26运行项目发现淘宝接口报错502,于是找到一个替代的接口,新浪接…
private static boolean isBoolIp(String ipAddress) { String ip = "(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)"; Pattern pattern = Pattern.compile(ip); Matcher matcher = pattern.matcher(ipAddress); re…
import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.net.InetAddress; import java.net.NetworkInterface; import java.net.SocketException; import java.util.ArrayList; import java.util.Enumeration; import java.util.List; public class IpU…
问题 用Java获取本机IP地址,需要处理: 1. 多块网卡. 2. 排除loopback设备.虚拟网卡 看似简单的代码,写起来还是要小心一些的. 方案 HBase客户端获取本机IP的代码提供了一个很好的参考.没有特殊需求的话,拷贝过去用吧:) // From HBase Addressing.Java private static InetAddress getIpAddress(AddressSelectionCondition condition) throws SocketExcepti…
这篇文章主要介绍了java编程实现获取机器IP地址及MAC地址的方法,实例分析了Java分别针对单网卡及多网卡的情况下获取服务器IP地址与MAC地址的相关技巧,需要的朋友可以参考下   本文实例讲述了java编程实现获取服务器IP地址及MAC地址的方法.分享给大家供大家参考,具体如下: 已测系统:windows linux unix 排除127.0.0.1 和 0.0.0.0.1等非正常IP import java.net.InetAddress; import java.net.Network…
java.net  类 InetAddress 此类表示互联网协议 (IP) 地址. 会抛出异常 UnknownHostException   直接已知子类:         Inet4Address, Inet6Address  没有构造函数,但是可以通过静态方法获取对象后,在完成其它功能的使用.  例如:    static InetAddress getLocalHost() 返回本地主机.         static InetAddress getByName(String host)…
I am trying to convert an address specified by an IP number or a name, both in String (i.e. localhost or 127.0.0.1), into an InetAdress object. There's no constructor but rather static methods that return an InetAddress. So if I get a host name it's…
The InetAddress is Java's representation of an IP address. Instances of this class are used together with UDP DatagramSockets and normal Socket's and ServerSocket's. Creating an InetAddress Instance InetAddress has no public contructor, so you must o…
/* * InetAddress类: * 用于标识网络上的硬件资源,表示互联网协议(ip)地址,是java对ip地址的封装. * 其实例对象包含以数字形式保存的IP地址,主机名. * InetAddress类提供了将主机名解析为IP地址(或反之)的方法. * * 1InetAddress对象的获取 InetAddress的构造函数不是公开的(public),所以需要通过它提供的静态方法来获取,有以下的方法: static InetAddress[] getAllByName(String hos…
针对网络通信的不同层次,Java提供的网络功能有四大类 InetAddress:用于标识网络上的硬件资源.(说白了就是IP地址的相关信息) URL:统一资源定位符,通过URL可以直接读取或写入网络上的数据 Sockets:使用TCP协议实现网络通信的Socket相关的类 Datagram:使用UDP协议,将数据保存在数据报中,通过网络进行通信.(通过在网络中发送数据报进而实现网络的通信) InetAddress类用于标识网络上的硬件资源,表示互联网协议(IP)协议. package zhang;…
计算机网络 是指将地理位置不同的具有独立功能的多台计算机及其外部设备,通过通信线路连接起来, 在网络操作系统,网络管理软件及网络通信协议的管理和协调下,实现资源共享和信息传递的计算机系统. 网络编程 就是用来实现网络互连的不同计算机上运行的程序间可以进行数据交换.   TCP/IP协议栈   应用层 传输层 网络层 网络接口层   大多数应用程序员仅仅涉及应用层和传输层   网络通信三要素   IP地址:InetAddress         网络中设备的标识,不易记忆,可用主机名 要想让网络中…
首先,你如果搜索“JAVA获取本机IP地址”,基本上搜到的资料全是无用的.比如这篇:http://www.cnblogs.com/zrui-xyu/p/5039551.html实际上的代码在复杂环境下是不准的 网上一个比较普遍的说法是InetAddress.getLocalHost().getHostAddress()似乎很简单,但忽略了一个问题,即IP地址在现在的网络环境更加复杂了,比如有Lan,WIFI,蓝牙热点,虚拟机网卡...即存在很多的网络接口(network interfaces),…
一:IP与InetAddress 在Java中支持网络通讯程序的开发,主要提供了两种通讯协议:TCP协议,UDP协议 可靠地连接传输,使用三方握手的方式完成通讯 不可靠的连接传输,传输的时候接受方不一定可以接受的到 在Java中的所有网络程序的开发类都在java.net包中存在 IP地址简介 IP地址是指互联网协议地址(英语:Internet Protocol Address,又译为网际协议地址),是IP Address的缩写.IP地址是IP协议提供的一种统一的地址格式,它为互联网上的每一个网络…
一.InetAddress 这个类主要表示IP地址.InetAddress封装了IP地址和域名.域名可以看做IP地址的一个别称,起这个别称的目的是为了便于记忆. 例如www.baidu.com 就是119.75.217.109的别称,在浏览器地址栏输入119.75.217.109同样可以访问百度首页.明显这个别称更好记忆. InetAddress封装了IP地址和域名,总之里面的Address就是IP地址,Name就是这个地址的别称. 1.1构造方法,改类的构造方法无法直接调用,需通过返回值为In…
InerAddress: /**IP地址:在网络上唯一标示一台计算机 * 端口号:标示计算机上不同的应用程序 * java.net.InetAddress类:此类表示互联网协议 (IP) 地址. * 常用方法: * getByName(String host) 在给定主机名的情况下确定主机的 IP 地址. * getHostName() 获取此 IP地址的主机名. * getHostAddress()返回 IP 地址字符串(以文本表现形式). * getLocalHost() 返回本地主机. *…
Java网络编程之InetAddress浅析 一.InetAddress综述 IP地址是IP使用的32位(IPv4)或者128位(IPv6)位无符号数字,它是传输层协议TCP,UDP的基础.InetAddress是Java对IP地址的封装,几乎所有的Java网络相关的类都和它有关系,例如:serversocket,socket,URL,DataGramSocket,DataGRamPacket等. InetAddress的实例对象包含以数字形式保存的IP地址,同时还可能包含主机名(如果使用主机名…
获取自己的IP地址 import java.net.InetAddress; import java.net.UnknownHostException; public class getip { public static void main(String[] args) throws UnknownHostException { /** * ip地址对象. InetAddress * @throws UnknownHostException * */ //获取本地主机地址对象 InetAddr…
/** * 取当前系统站点本地地址 linux下 和 window下可用 * * @return */ public static String getLocalIP() { String sIP = ""; InetAddress ip = null; try { // 如果是Windows操作系统 if (isWindowsOS()) { ip = InetAddress.getLocalHost(); } // 如果是Linux操作系统 else { boolean bFindI…
public class IpTool { public static void main(String[] args) { IpTool ipTool=new IpTool(); System.out.println(ipTool.getLocalIP()); } /** * * 判斷當前操作是否Windows. * * @return true---是Windows操作系統 */ private boolean isWindowsOS() { boolean isWindowsOS = fa…