Java Ping扫描,具有输入范围的能力
目前,我正在尝试为用户输入的范围创建ping扫描 为此,我在互联网上尝试了各种来源,但它们都非常模糊,或者我似乎无法让它们发挥作用,我认为我对java非常陌生 有一个来源,我试图完全打字,但似乎无法工作,位于- 我尝试使用的代码是Java Ping扫描,具有输入范围的能力,java,netbeans-7.4,Java,Netbeans 7.4,目前,我正在尝试为用户输入的范围创建ping扫描 为此,我在互联网上尝试了各种来源,但它们都非常模糊,或者我似乎无法让它们发挥作用,我认为我对java非常陌生 有一个来源,我试图完全打字,但似乎无法工作,位于- 我尝试使用的代码是 import java.net.Inet4Address; import java.net.InetAddress; import java.util.Arrays; import java.io.IOException; import java.io.*;
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.net.Inet4Address;
导入java.net.InetAddress;
导入java.util.array;
导入java.io.IOException;
导入java.io.*;
导入java.util.Scanner;
进口jpcap。*;
导入jpcap.packet.*;
公共类ARP{
公共静态void main(字符串[]args)引发IOException{
//获取网络接口列表
NetworkInterface[]devices=JpcapCaptor.getDeviceList();
//对于每个网络接口
对于(inti=0;i
上面的代码有很多错误,当我尝试使用它时,我不完全确定我做错了什么
同样,我对java非常陌生,如果有人能给我指出正确的方向,那将是一个很大的帮助
我也尝试过使用这个youtube教程,其中包括端口扫描和Ping扫描,但运气不太好
任何帮助都将不胜感激
谢谢
杰米我从这里得到的这段代码是ping设备。您可以轻松地将其修改为ping一系列设备
import java.io.*;
import java.util.*;
public class JavaPingExampleProgram
{
public static void main(String args[])
throws IOException
{
// create the ping command as a list of strings
JavaPingExampleProgram ping = new JavaPingExampleProgram();
List<String> commands = new ArrayList<String>();
commands.add("ping");
commands.add("-c");
commands.add("5");
commands.add("74.125.236.73");
ping.doCommand(commands);
}
public void doCommand(List<String> command)
throws IOException
{
String s = null;
ProcessBuilder pb = new ProcessBuilder(command);
Process process = pb.start();
BufferedReader stdInput = new BufferedReader(new InputStreamReader(process.getInputStream()));
BufferedReader stdError = new BufferedReader(new InputStreamReader(process.getErrorStream()));
// read the output from the command
System.out.println("Here is the standard output of the command:\n");
while ((s = stdInput.readLine()) != null)
{
System.out.println(s);
}
// read any errors from the attempted command
System.out.println("Here is the standard error of the command (if any):\n");
while ((s = stdError.readLine()) != null)
{
System.out.println(s);
}
}
import java.io.*;
导入java.util.*;
公共类JavapingExample程序
{
公共静态void main(字符串参数[])
抛出IOException
{
//将ping命令创建为字符串列表
JavaPingExampleProgram ping=新的JavaPingExampleProgram();
List命令=new ArrayList();
命令。添加(“ping”);
命令。添加(“-c”);
命令。添加(“5”);
命令。添加(“74.125.236.73”);
ping.docomand(命令);
}
公共无效doCommand(列表命令)
抛出IOException
{
字符串s=null;
ProcessBuilder pb=新的ProcessBuilder(命令);
Process进程=pb.start();
BufferedReader stdInput=新的BufferedReader(新的InputStreamReader(process.getInputStream());
BufferedReader stdError=新的BufferedReader(新的InputStreamReader(process.getErrorStream());
//读取命令的输出
System.out.println(“这是命令的标准输出:\n”);
而((s=stdInput.readLine())!=null)
{
系统输出打印项次;
}
//从尝试的命令中读取任何错误
System.out.println(“这是命令的标准错误(如果有):\n”);
而((s=stdError.readLine())!=null)
{
系统输出打印项次;
}
}
这似乎对我很有效,感谢出于好奇,我如何从ping扫描中检索mac地址,因为我不确定从哪里开始,只是查了一下,但我确实在stackflow上看到了这篇文章。如果你不介意的话,你应该将答案标记为正确。有关mac地址位,请查看