目前我正在尝试创建的是对用户输入范围的 ping 扫描。
我为此尝试了互联网上的各种资源,但它们非常模糊,或者我似乎无法让它们工作,记住我对 java 很陌生。
我试图完全输入但似乎无法开始工作的一个来源位于 - http://www.coderanch.com/t/205721/sockets/java/Determining-computers-network
我尝试使用的代码是......
import java.net.Inet4Address;
import java.net.InetAddress;
import java.util.Arrays;
import java.io.IOException;
import java.io.*;
import java.util.Scanner;
import jpcap.*;
import jpcap.packet.*;
public class ARP{
public static void main(String[] args) throws IOException{
//Obtain the list of network interfaces
NetworkInterface[] devices = JpcapCaptor.getDeviceList();
//for each network interface
for (int i = 0; i < devices.length; i++) {
//print out its name and description
System.out.println(i+": "+devices[i].name + "(" + devices[i].description+")");
//print out its datalink name and description
System.out.println(" datalink: "+devices[i].datalink_name + "(" + devices[i].datalink_description+")");
//print out its MAC address
System.out.print(" MAC address:");
for (byte b : devices[i].mac_address)
System.out.print(Integer.toHexString(b&0xff) + ":");
System.out.println();
//print out its IP address, subnet mask and broadcast address
for (NetworkInterfaceAddress a : devices[i].addresses)
System.out.println(" address:"+a.address + " " + a.subnet + " "+ a.broadcast);
}
//NetworkInterface[] devices = JpcapCaptor.getDeviceList();
int index =1; // set index of the interface that you want to open.
//Open an interface with openDevice(NetworkInterface intrface, int snaplen, boolean promics, int to_ms)
final JpcapCaptor captor=JpcapCaptor.openDevice(devices[index], 65535, false, 20);
//JpcapCaptor captor=JpcapCaptor.openDevice(device[1], 65535, false, 20);
//call processPacket() to let Jpcap call PacketPrinter.receivePacket() for every packet capture.
//captor.processPacket(10,new PacketPrinter());
//System.out.println(packet);
//captor.close();
}
}
当我尝试使用上面的代码时,它有很多错误,我不完全确定我做错了什么。
同样,我对 java 还是很陌生,如果有人能指出我正确的方向,那将是一个很大的帮助。
我也尝试过使用这个 youtube 教程,它涵盖了端口扫描和 Ping Sweeping,但运气不佳。
http://www.youtube.com/watch?v=FvycwyAat6s
任何帮助将不胜感激,
谢谢,
杰米