如何使用Java扫描无线网络 [英] How Can Scan Wireless Network Using Java

查看:80
本文介绍了如何使用Java扫描无线网络的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

推荐答案

没有为此的API.但是您可以使用某些设备并通过命令行触发它们.这完全取决于您使用的硬件/操作系统/软件.
There is no API for that. But you can use some devices and trigger them via command line. It all depends on what Hardware/OS/Software you use.


您好 亲爱的朋友,我已经通过这种方式自己解决了这个问题(如下所示),但是(一个问题是它速度较慢),这向我显示了与我的网络连接的所有计算机(笔记本电脑[无线]),但是现在我想展示与我的网络连接的android,BlackBerry设备如何执行此操作,请任何人帮忙.


公共类NetworkPing扩展JFrame {
public NetworkPing(){
}
公共静态void main(String [] args)引发UnknownHostException {
尝试{
second_testmethod();
} catch(IOException e){
//TODO自动生成的捕获块
e.printStackTrace();
}
}
公共静态void second_testmethod()引发IOException {
InetAddress本地主机= null;
尝试{
本地主机= InetAddress.getLocalHost();
} catch(UnknownHostException e){
e.printStackTrace();
}
//此代码假定使用了IPv4
byte [] ip = localhost.getAddress();
for(int i = 0; i< 255; i ++)
{
ip [3] =(byte)i;
InetAddress地址= InetAddress.getByAddress(ip);
如果(address.isReachable(1000))
{
System.out.println("can b ping");
//机器已打开并且可以被ping通
}
否则((address.getHostAddress().equals(address.getHostName()))
{
System.out.println(名称为......" + address.getHostName()+"\ tIP为......." + address.getHostAddress());
//在DNS查找中已知计算机
}
其他
{
System.out.println("nothing");
//主机地址和主机名相等,这意味着无法解析主机名
}
}
}
}//课程结束
Hi dear friends I have solve this myself in this way(given below) but(one problem with this is that it is more slow),this is showing me all computers(laptop[wireless]) connected with my network but now I want to show android, BlackBerry devices connected with my network how can I do this can any one help me please.


public class NetworkPing extends JFrame{
public NetworkPing() {
}
public static void main(String[] args) throws UnknownHostException {
try {
second_testmethod();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public static void second_testmethod() throws IOException{
InetAddress localhost = null;
try {
localhost = InetAddress.getLocalHost();
} catch (UnknownHostException e) {
e.printStackTrace();
}
// this code assumes IPv4 is used
byte[] ip = localhost.getAddress();
for (int i = 0; i < 255; i++)
{
ip[3] = (byte)i;
InetAddress address = InetAddress.getByAddress(ip);
if (address.isReachable(1000))
{
System.out.println("can b pinged");
// machine is turned on and can be pinged
}
else if (!address.getHostAddress().equals(address.getHostName()))
{
System.out.println("Name is......"+address.getHostName()+"\tIP is......."+address.getHostAddress());
// machine is known in a DNS lookup
}
else
{
System.out.println("nothing");
// the host address and host name are equal, meaning the host name could not be resolved
}
}
}
}//end of class


这篇关于如何使用Java扫描无线网络的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆