Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
beefproject
GitHub Repository: beefproject/beef
Path: blob/master/modules/network/ping_sweep_java/pingSweep.java
1155 views
1
/*
2
* Copyright (c) 2006-2025Wade Alcorn - [email protected]
3
* Browser Exploitation Framework (BeEF) - https://beefproject.com
4
* See the file 'doc/COPYING' for copying permission
5
*/
6
7
import java.applet.Applet;
8
import java.io.IOException;
9
import java.net.InetAddress;
10
import java.net.UnknownHostException;
11
import java.util.ArrayList;
12
import java.util.List;
13
14
/*
15
* Coded by Michele "antisnatchor" Orru' for the BeEF project.
16
* Given a single IP or IP range, check without hosts are alive (ping sweep).
17
*/
18
public class pingSweep extends Applet {
19
20
public static String ipRange = "";
21
public static int timeout = 0;
22
public static List<InetAddress> hostList;
23
24
public pingSweep() {
25
super();
26
return;
27
}
28
29
public void init(){
30
ipRange = getParameter("ipRange");
31
timeout = Integer.parseInt(getParameter("timeout"));
32
}
33
34
//called from JS
35
public static int getHostsNumber(){
36
try{
37
hostList = parseIpRange(ipRange);
38
}catch(UnknownHostException e){ //do something
39
40
}
41
return hostList.size();
42
}
43
44
//called from JS
45
public static String getAliveHosts(){
46
String result = "";
47
try{
48
result = checkHosts(hostList);
49
}catch(IOException io){
50
//do something
51
}
52
return result;
53
}
54
55
private static List<InetAddress> parseIpRange(String ipRange) throws UnknownHostException {
56
57
List<InetAddress> addresses = new ArrayList<InetAddress>();
58
if (ipRange.indexOf("-") != -1) { //multiple IPs: ipRange = 172.31.229.240-172.31.229.250
59
String[] ips = ipRange.split("-");
60
String[] octets = ips[0].split("\\.");
61
int lowerBound = Integer.parseInt(octets[3]);
62
int upperBound = Integer.parseInt(ips[1].split("\\.")[3]);
63
64
for (int i = lowerBound; i <= upperBound; i++) {
65
String ip = octets[0] + "." + octets[1] + "." + octets[2] + "." + i;
66
addresses.add(InetAddress.getByName(ip));
67
}
68
} else { //single ip: ipRange = 172.31.229.240
69
addresses.add(InetAddress.getByName(ipRange));
70
}
71
return addresses;
72
}
73
74
private static String checkHosts(List<InetAddress> inetAddresses) throws IOException {
75
String alive = "";
76
for (InetAddress inetAddress : inetAddresses) {
77
if (inetAddress.isReachable(timeout)) {
78
alive += inetAddress.toString() + "\n";
79
}
80
}
81
return alive;
82
}
83
}
84
85