资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

javaip代码,java ip

求java获取手机ip或者平板ip的代码

//获取ip地址

创新互联建站成立10余年来,这条路我们正越走越好,积累了技术与客户资源,形成了良好的口碑。为客户提供成都做网站、成都网站设计、网站策划、网页设计、国际域名空间、网络营销、VI设计、网站改版、漏洞修补等服务。网站是否美观、功能强大、用户体验好、性价比高、打开快等等,这些对于网站建设都非常重要,创新互联建站通过对建站技术性的掌握、对创意设计的研究为客户提供一站式互联网解决方案,携手广大客户,共同发展进步。

public String getLocalIpAddress()

{

try {

String ipv4;

ArrayListNetworkInterface nilist = Collections.list(NetworkInterface.getNetworkInterfaces());

for (NetworkInterface ni: nilist)

{

ArrayListInetAddress ialist = Collections.list(ni.getInetAddresses());

for (InetAddress address: ialist)

{

if (!address.isLoopbackAddress() InetAddressUtils.isIPv4Address(ipv4=address.getHostAddress()))

{

return ipv4;

}

}

}

} catch (SocketException ex)

{

//Log.e(LOG_TAG, ex.toString());

}

return null;

}

谁清楚java代码获取ip地址方法是什么

1、如果服务器如果没有采用反向代理,而且客户端没有用正向代理的话,那么可以获取客户端的真实IP地址request.getRemoteAddr()

2、如果服务器如果没有采用反向代理,而且客户端有用正向代理的话,那么通过request.getRemoteAddr()获取客户端的IP地址是客户端 的代理服务器的地址,并不是客户端的真实地址

3、如果客户端使用的是多层代理的话,服务器获得的客户端地址是客户端的最外围代理服务器的地址如果服务器如果采用反向代理服务器,不管客户端采用的是何种方式访问服务器

java获取局域网ip地址 具体代码

import java.io.*;

import java.util.*;

import java.net.InetAddress;

public class Ip{

static public HashMap ping; //ping 后的结果集

public HashMap getPing(){ //用来得到ping后的结果集

return ping;

}

//当前线程的数量, 防止过多线程摧毁电脑

static int threadCount = 0;

public Ip() {

ping = new HashMap();

}

public void Ping(String ip) throws Exception{

//最多30个线程

while(threadCount30)

Thread.sleep(50);

threadCount +=1;

PingIp p = new PingIp(ip);

p.start();

}

public void PingAll() throws Exception{

//首先得到本机的IP,得到网段

InetAddress host = InetAddress.getLocalHost();

String hostAddress = host.getHostAddress();

int k=0;

k=hostAddress.lastIndexOf(".");

String ss = hostAddress.substring(0,k+1);

for(int i=1;i =255;i++){ //对所有局域网Ip

String iip=ss+i;

Ping(iip);

}

//等着所有Ping结束

while(threadCount0)

Thread.sleep(50);

}

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

Ip ip= new Ip();

ip.PingAll();

java.util.Set entries = ping.entrySet();

Iterator iter=entries.iterator();

String k;

while(iter.hasNext()){

Map.Entry entry=(Map.Entry)iter.next();

String key=(String)entry.getKey();

String value=(String)entry.getValue();

if(value.equals("true"))

System.out.println(key+"--"+value);

}

}

class PingIp extends Thread{

public String ip; // IP

public PingIp(String ip){

this.ip=ip;

}

public void run(){

try{

Process p= Runtime.getRuntime().exec ("ping "+ip+ " -w 300 -n 1");

InputStreamReader ir = new InputStreamReader(p.getInputStream());

LineNumberReader input = new LineNumberReader (ir);

//读取结果行

for (int i=1 ; i 7; i++)

input.readLine();

String line= input.readLine();

if (line.length() 17 || line.substring(8,17).equals("timed out"))

ping.put(ip,"false");

else

ping.put(ip,"true");

//线程结束

threadCount -= 1;

}catch (IOException e){}

}

}

}

用java语言,写一段代码,比较两个ip地址的大小

你好,可以把IP去掉‘.’,然后再比较

private bool validateIP(string startIP,string endIP)

{

// 分离出ip中的四个数字位

string[] startIPArray = startIP.Split('.');

string[] endIPArray = endIP.Split('.');

// 取得各个数字

long[] startIPNum = new long[4];

long[] endIPNum = new long[4];

for (int i = 0; i 4; i++)

{

startIPNum[i] = long.Parse(startIPArray[i].Trim());

endIPNum[i] = long.Parse(endIPArray[i].Trim());

}

// 各个数字乘以相应的数量级

long startIPNumTotal = startIPNum[0] * 256 * 256 * 256 + startIPNum[1] * 256 * 256 + startIPNum[2] * 256 + startIPNum[3];

long endIPNumTotal = endIPNum[0] * 256 * 256 * 256 + endIPNum[1] * 256 * 256 + endIPNum[2] * 256 + endIPNum[3];

if (startIPNumTotal endIPNumTotal)

{

return false;

}

else

{

return true;

}

}

局域网中的电脑如何用java代码取得出口IP?

public class GetRealIp {

public static void main(String[] args) throws SocketException {

System.out.println(GetRealIp.getRealIp());

}

public static String getRealIp() throws SocketException {

String localip = null;// 本地IP,如果没有配置外网IP则返回它

String netip = null;// 外网IP

EnumerationNetworkInterface netInterfaces =

NetworkInterface.getNetworkInterfaces();

InetAddress ip = null;

boolean finded = false;// 是否找到外网IP

while (netInterfaces.hasMoreElements() !finded) {

NetworkInterface ni = netInterfaces.nextElement();

EnumerationInetAddress address = ni.getInetAddresses();

while (address.hasMoreElements()) {

ip = address.nextElement();

if (!ip.isSiteLocalAddress()

!ip.isLoopbackAddress()

ip.getHostAddress().indexOf(":") == -1) {// 外网IP

netip = ip.getHostAddress();

finded = true;

break;

} else if (ip.isSiteLocalAddress()

!ip.isLoopbackAddress()

ip.getHostAddress().indexOf(":") == -1) {// 内网IP

localip = ip.getHostAddress();

}

}

}

if (netip != null !"".equals(netip)) {

return netip;

} else {

return localip;

}

}

}

自己写了一个帮你实现,希望对你有帮助


分享标题:javaip代码,java ip
URL标题:http://cdkjz.cn/article/hcigce.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

业务热线:400-028-6601 / 大客户专线   成都:13518219792   座机:028-86922220