Java 扫描局域网IP

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.InetAddress;

public class IP {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		try {
			//Runtime.getRuntime().exec("ping 192.168.1.1").destroy();
			//Runtime.getRuntime().exec("for /l %i in (1,1,255) do " +
			//		"(ping -w 2 -n 1 192.168.1.%i)").destroy();
			
			String localIP=InetAddress.getLocalHost().getHostAddress();
			String[] net=localIP.split("\\.");
			
			int j=Integer.parseInt(net[2]);
			for(int i=1;i<256;i++){
				Runtime.getRuntime().exec("ping -w 2 -n 1 192.168."+j+"."+i).destroy();
			}
			
			Process p=Runtime.getRuntime().exec("arp -a");
			BufferedReader br=new BufferedReader(new InputStreamReader(p.getInputStream()));
			
			br.readLine();
			br.readLine();
			br.readLine();
			String temp=null;
			while(((temp=br.readLine())!=null&&!temp.isEmpty())){
				System.out.println(temp.trim().split(" ")[0]);
				
			}
			
			//String localIP=InetAddress.getLocalHost().getHostAddress();
			//String[] net=localIP.split("\\.");
			
			//System.out.println(net[2]);
			
			//System.out.println(InetAddress.getLocalHost().getHostAddress());
			p.destroy();
			br.close();
			
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		
	}


}
生成海报

Saiyintai

软件测试工程师

暂无评论

相关推荐

Java 项目所需的包

包名 描述 所属层次 xx.xx.domain 存放系统的JavaBean类(只包含简单的属性以及属性对应的get和set方法,不包含具体的业 …

微信扫一扫,分享到朋友圈

Java 扫描局域网IP

Optimized by WPJAM Basic