资讯

精准传达 • 有效沟通

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

javaip生成代码 java代码自动生成

求java中string类型转化为ip地址的代码,可以是任意字符串,如果不是ip的话做错误处理

用split(“.”)将字符串分割成四段,再转换成数字,最后转换成二进制串,就是ip.。如果不够四段或者不是数字等等就是错误

创新互联建站服务项目包括台江网站建设、台江网站制作、台江网页制作以及台江网络营销策划等。多年来,我们专注于互联网行业,利用自身积累的技术优势、行业经验、深度合作伙伴关系等,向广大中小型企业、政府机构等提供互联网行业的解决方案,台江网站推广取得了明显的社会效益与经济效益。目前,我们服务的客户以成都为中心已经辐射到台江省份的部分城市,未来相信会继续扩大服务区域并继续获得客户的支持与信任!

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

//获取ip地址

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地址 具体代码

import java.io.*;

import java.util.*;

import java点虐 .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){}

}

}

}


分享标题:javaip生成代码 java代码自动生成
文章网址:http://cdkjz.cn/article/ddipgde.html
多年建站经验

多一份参考,总有益处

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

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

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