-
Notifications
You must be signed in to change notification settings - Fork 6
/
test1_ip_pairs_generate.sh
executable file
·54 lines (43 loc) · 1.17 KB
/
test1_ip_pairs_generate.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
52
53
54
#!/bin/sh
# here we generate a list of random node-pairs
# out of our IP-list and store that into the file './test1_ip_pairs'
# later we iterate over that list, starting a data-transmission
# and measuring the transfered bytes. this is done for each protocol.
FILE_IPLIST="${1:-./routers}"
OUT='./test1_ip_pairs.txt'
random_integer()
{
local start="${1:-0}"
local end="${2:-256}"
local seed diff random out
seed="$( hexdump -n 2 -e '/2 "%u"' /dev/urandom )" # e.g. 0...65536
[ $end -gt 65536 ] && seed=$(( seed * seed ))
diff=$(( end + 1 - start ))
[ ${diff:-0} -gt 0 ] || diff=1 # happens with input start=1 end=0
random=$(( seed % diff )) # result: integer somewhere between 0...$diff - divisor_valid
out=$(( start + random ))
echo "${out:-$start}"
}
get_random_ip()
{
local i=1
local max="$( wc -l <"$FILE_IPLIST" )"
local random="$( random_integer 1 $max )"
local line
while read -r line; do
ip="$line"
[ $i -eq $random ] && break
i=$(( i + 1 ))
done <"$FILE_IPLIST"
echo "$ip"
}
MAX=100
I=1
while [ $I -lt $MAX ]; do
IP1="$( get_random_ip )"
IP2="$( get_random_ip )"
[ "$IP1" = "$IP2" ] || {
echo "$IP1 $IP2"
I=$(( I + 1 ))
}
done >"$OUT"