forked from seawolfiot/seawolf.io
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpost-ip
executable file
·73 lines (63 loc) · 1.52 KB
/
post-ip
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
67
68
69
70
71
72
73
#!/bin/bash
###############################################################
#
# ./post-ip
#
# post hostname, nic name and ip info to
#
# https://seawolf.io/post
#
# SEAWOLF.IO keeps user posted data for maximum 10 minutes.
# After 10 minutes, the data will be destroyed. Within the
# 10 minutes, the posted data can be accessed only from the
# same IP where the data are posted. It is a free service
# provided by Seawolf Technologies Inc.
#
# by Sam Wen @ 10/27/2018
#
###############################################################
# wait until network links are up
#
while true; do
uplinks=$(ip -o link | grep -v '^.: lo:' | awk -F ':| ' '{print $3, $11}' | grep -c 'UP')
if [ $uplinks -gt 0 ]; then
break
else
sleep 1
fi
done
# wait at least 5 minutes for all up links have ips
#
count=0
while true; do
ips=$(ip -o address | grep -v '^.: \(lo\|.* inet6 \)' | wc -l)
if [ $ips -eq $uplinks ]; then
break
elif [ $ips -eq 0 ]; then
sleep 1
elif [ $count -gt 300 ]; then
break
else
((count++))
sleep 1
fi
done
ips=($(ip -o address | grep -v '^.: \(lo\|.* inet6 \)' | awk -F ' |/' '{print $2, $7}'))
# generate json string
#
ips_count=${#ips[*]}
ips_row=$((ips_count/2))
json="{\"hostname\": \"$(hostname)\""
for ((i=0; i<$ips_row; i++));
do
start=$((i*2))
iface=${ips[$start]}
ip=${ips[$((start+1))]}
line="\"$iface\": \"$ip\""
json="$json, $line"
done
json="$json}"
echo $json
# post it
#
curl -s -d "$json" -H "Content-Type: application/json" -X POST https://seawolf.io/post