-
Notifications
You must be signed in to change notification settings - Fork 0
/
P_NetworkPing.pde
66 lines (61 loc) · 1.61 KB
/
P_NetworkPing.pde
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
class networkPing {
String IP;
int index;
int variableTimer = 5;
int stopwatch;
networkPing(int tempIndex) {
stopwatch = millis();
this.index = tempIndex;
this.IP = "";
}
void send() {
int timeOut = 1000;
gui.resetTimer = true;
if (this.IP.length() > 0) {
try {
InetAddress inet = InetAddress.getByName(this.IP);
if (inet.isReachable(timeOut)) {
heart.get(this.index).reachable = 2;
println("From: " + this.index + ", " + this.IP + " is reachable.");
} else {
heart.get(this.index).reachable = 1;
println("From: " + this.index + ", " + this.IP + " NOT reachable.");
}
} catch (Exception e) {
heart.get(this.index).reachable = 1;
println("Exception:" + e.getMessage());
}
} else {
heart.get(this.index).reachable = 0;
}
}
void find(String subnet) {
int timeout = 100;
int found = 0;
for (int i = 1; i < 255; i++) {
String host = subnet + "." + i;
try {
InetAddress address = InetAddress.getByName(host);
if (address.isReachable(timeout)) {
ipField.get(found).userIP = host;
ping.get(found).IP = host;
println(host + " is reachable " + str(found));
found++;
println(address.getHostName());
}
} catch (Exception e) {
}
}
}
void request(String tempIP) {
if (this.IP != "IP ADDRESS") {
this.IP = tempIP;
}
}
void timer() {
if (millis() > stopwatch && !pauseTimer && startUp) {
stopwatch += variableTimer * 1000;
send();
}
}
}