Added PingSweepJava module: as the PingSweep module works only on FF, this one uses an unsigned applet to do the same thing on all the other browsers :-)
git-svn-id: https://beef.googlecode.com/svn/trunk@1405 b87d56ec-f9c0-11de-8c8a-61c5e9addfc9
This commit is contained in:
77
modules/network/ping_sweep_java/pingSweep.java
Normal file
77
modules/network/ping_sweep_java/pingSweep.java
Normal file
@@ -0,0 +1,77 @@
|
||||
import java.applet.Applet;
|
||||
import java.io.IOException;
|
||||
import java.net.InetAddress;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/*
|
||||
* Coded by Michele "antisnatchor" Orru' for the BeEF project.
|
||||
* Given a single IP or IP range, check without hosts are alive (ping sweep).
|
||||
*/
|
||||
public class pingSweep extends Applet {
|
||||
|
||||
public static String ipRange = "";
|
||||
public static int timeout = 0;
|
||||
public static List<InetAddress> hostList;
|
||||
|
||||
public pingSweep() {
|
||||
super();
|
||||
return;
|
||||
}
|
||||
|
||||
public void init(){
|
||||
ipRange = getParameter("ipRange");
|
||||
timeout = Integer.parseInt(getParameter("timeout"));
|
||||
}
|
||||
|
||||
//called from JS
|
||||
public static int getHostsNumber(){
|
||||
try{
|
||||
hostList = parseIpRange(ipRange);
|
||||
}catch(UnknownHostException e){ //do something
|
||||
|
||||
}
|
||||
return hostList.size();
|
||||
}
|
||||
|
||||
//called from JS
|
||||
public static String getAliveHosts(){
|
||||
String result = "";
|
||||
try{
|
||||
result = checkHosts(hostList);
|
||||
}catch(IOException io){
|
||||
//do something
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private static List<InetAddress> parseIpRange(String ipRange) throws UnknownHostException {
|
||||
|
||||
List<InetAddress> addresses = new ArrayList<InetAddress>();
|
||||
if (ipRange.indexOf("-") != -1) { //multiple IPs: ipRange = 172.31.229.240-172.31.229.250
|
||||
String[] ips = ipRange.split("-");
|
||||
String[] octets = ips[0].split("\\.");
|
||||
int lowerBound = Integer.parseInt(octets[3]);
|
||||
int upperBound = Integer.parseInt(ips[1].split("\\.")[3]);
|
||||
|
||||
for (int i = lowerBound; i <= upperBound; i++) {
|
||||
String ip = octets[0] + "." + octets[1] + "." + octets[2] + "." + i;
|
||||
addresses.add(InetAddress.getByName(ip));
|
||||
}
|
||||
} else { //single ip: ipRange = 172.31.229.240
|
||||
addresses.add(InetAddress.getByName(ipRange));
|
||||
}
|
||||
return addresses;
|
||||
}
|
||||
|
||||
private static String checkHosts(List<InetAddress> inetAddresses) throws IOException {
|
||||
String alive = "";
|
||||
for (InetAddress inetAddress : inetAddresses) {
|
||||
if (inetAddress.isReachable(timeout)) {
|
||||
alive += inetAddress.toString() + "\n";
|
||||
}
|
||||
}
|
||||
return alive;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user