-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun.sh
executable file
·51 lines (40 loc) · 1.02 KB
/
run.sh
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
#!/usr/bin/env bash
DIR="$(dirname "$0")";
exec 3>&1
set -e;
do_a_ip() {
local amount="$1"
local start="$2"
local start_ip="$3";
local to="$(echo "${amount}"$'\n'"${start}"$'\n'"-1" | awk '{ sum += $1; } END { print sum; }')";
local ips="";
local ip="";
log "Spawning IPs"
while read number; do
ip="$start_ip:$(printf "%x" "${number}" | colonize)"
create_ip "${ip}";
ips="${ips},${ip}";
log "$number = $ip = $(echo -n "$ips" | wc -c)";
done <<< "$(seq "$start" "$to")"
log "Running Hebi-Neko";
node "$DIR/index.js" "$(echo "$ips" | sed 's/,$//')"
}
log() {
echo $@ 1>&3;
}
create_ip() {
log "Creating IP: $1";
result="$(sudo ip address add "$1/64" dev "${DEV:-eth0}" 2>&1 || true)";
if ! ( [ -z "$result" ] || echo "$result" | grep -q "File exists"); then
log "Creating IP failed: $result";
exit 1;
fi
#true;
}
colonize () {
rev | sed 's/[0-9a-f]\{4\}/\0:/g' | rev | sed 's/^://'
}
main() {
do_a_ip $@;
}
main $@;