2013-12-08 2 views
0

현재 내가 작성하려고하는 것은 사용자가 입력 한 범위의 핑 스윕입니다.범위를 입력 할 수있는 Ping Sweep

나는 이것에 대한 인터넷에서 다양한 소스를 시도했지만 매우 모호하거나 그냥 작동하지 않는 것처럼 보입니다.

하나의 소스는 내가 완전히 입력 시도했지만에 위치한 작업에 도착하는 것 캔트 - 위의 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(); 

} 
} 

코드 내가 그것을 사용하려고 할 때 많은 오류가있다, 나는 무엇을 잘못하고 있는지 완전히 확신하지 못한다.

또 다시 나는 자바에 매우 익숙하며 누군가가 올바른 방향으로 나를 가리킬 수 있다면 큰 도움이 될 것이다.

나는 또한 포트 스캐닝과 핑 스윕을 다루는 유튜브 튜토리얼을 사용하려고 시도했지만 많은 행운은 없었습니다.

http://www.youtube.com/watch?v=FvycwyAat6s

어떤 도움도 대단히 감사하겠습니다,

감사합니다,

제이미

답변

1

내가 여기 https://stackoverflow.com/a/14110872/868040에서 가져온이 코드는 장치를 핑. 이 장치를 쉽게 수정하여 다양한 장치를 핑 (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); 
    } 
    } 
+0

나를 위해 일한, 어떻게 호기심 덕분에 난 그냥 고개를하지만 난 그대로 stackflow 여기에이 게시물을 얻을, 맥 확실히 시작하지 메신저로 핑 스윕에서 adresses 검색 할 것입니다. – user3080543

+0

MAC 주소 비트가 마음에 들지 않으면 대답을 올바르게 표시해야합니다. http://www.mkyong.com/java/how-to-get-mac-address-in-java를 확인하십시오./ –

+0

이 코드를 ips 범위로 수정하는 방법? – Grant