-
Notifications
You must be signed in to change notification settings - Fork 6
/
define_all_ipaddresses.sh
executable file
·192 lines (146 loc) · 7.93 KB
/
define_all_ipaddresses.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
#!/bin/bash
make_cwd=`pwd`
if [ ! -d ./upnp ]; then
mkdir ./upnp
fi
if [ ! -f ./upnp/bin/upnpc ]; then
cd ./upnp && cwd=`pwd` && cd .. &&
cd external/miniupnp/miniupnpc && {
INSTALLPREFIX=$cwd make install && make clean && echo "miniUPnP client FOR THIS MAKE was installed - OK"; \
} &> make_out.txt
fi
cd $make_cwd
{
echo -n $'
PLEASE TURN OFF some OpenVPN/VPN services if you have!
It will help to define correct network configuration.
Now your IP addresses will be defined. UPnP support will be tested. Your real
public and router IP addresses will be defined.
Are you ready?
Please press ENTER when you will be ready! Waiting your answer..... '; read -s; echo " OK"
UPNPC_RUN=${UPNPC_RUN:-LD_LIBRARY_PATH=./upnp/lib ./upnp/bin/upnpc}
# LOCAL LISTEN IP ADDRESS
if [ `/sbin/ifconfig | grep 'inet '|sed -r -e 's/[^0-9]+([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+).*/\1/'|grep -vE '^127\.'|wc -l` -gt 1 ]; then /sbin/ifconfig | grep 'inet '|sed -r -e 's/[^0-9]+([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+).*/\1/'|grep -vE '^127\.'|awk 'BEGIN{a=1}{print a") "$1; a++}' > $$.tmp; echo $'\n\nYou have some network interfaces not one.\nPlease choose your local IP address of interface for future bitcoin services: \n\n'; cat $$.tmp; echo -n 'Your choose? [1, 2, ...] '; read number; listen_ip=`grep $number') ' $$.tmp|sed -e 's#'$number') ##'`; rm -f $$.tmp; else listen_ip=`/sbin/ifconfig | grep 'inet '|sed -r -e 's/[^0-9]+([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+).*/\1/'|grep -vE '^127\.'`; fi
BITCOIN_KIT_LOCAL_IP=$listen_ip
UPNPC_RUN="${UPNPC_RUN} -m $listen_ip"
echo -n $'\nPlease wait ...'
{
upnp_public_ip=$(eval $UPNPC_RUN -s|grep 'ExternalIPAddress = '|sed -e 's#ExternalIPAddress = ##')
} &>/dev/null
echo
[ "x$upnp_public_ip" != "x" ] && BITCOIN_KIT_UPNP_SUPPORT='Yes' || BITCOIN_KIT_UPNP_SUPPORT='No'
[ "x$BITCOIN_KIT_UPNP_SUPPORT" == "xYes" ] && BITCOIN_KIT_EXTERNAL_ROUTER_IP=$upnp_public_ip || BITCOIN_KIT_EXTERNAL_ROUTER_IP='Unknown'
# REAL PUBLIC IP address through ipinfo.io site
public_ip=`wget http://ipinfo.io/ip -qO -`
BITCOIN_KIT_REAL_PUBLIC_IP=$public_ip
if [ "x$upnp_public_ip" != "x" -a "$upnp_public_ip" != $public_ip ]; then
public_ip=0.0.0.0
elif [ "x$upnp_public_ip" == "x" -o "x$upnp_public_ip" != "x$public_ip" ]; then
public_ip=0.0.0.0
fi
[ $listen_ip == $public_ip ] && BITCOIN_KIT_BEHIND_ROUTER='No' || BITCOIN_KIT_BEHIND_ROUTER='Yes'
BITCOIN_KIT_SHOULD_CONFIGURE_ROUTER_PORT_FORWARDING='No'
[ $BITCOIN_KIT_BEHIND_ROUTER == 'No' ] && BITCOIN_KIT_POSSIBLE_INCOMING_CONNECTIONS='Yes'
[ $BITCOIN_KIT_BEHIND_ROUTER == 'Yes' \
-a \
$BITCOIN_KIT_UPNP_SUPPORT == 'Yes' \
-a \
$BITCOIN_KIT_EXTERNAL_ROUTER_IP == $BITCOIN_KIT_REAL_PUBLIC_IP \
] && { BITCOIN_KIT_POSSIBLE_INCOMING_CONNECTIONS='Yes'; BITCOIN_KIT_NOTICES=$BITCOIN_KIT_NOTICES$'* Incoming connections will be available by auto\n through UPnP service of your router\n'; }
[ $BITCOIN_KIT_BEHIND_ROUTER == 'Yes' \
-a \
$BITCOIN_KIT_UPNP_SUPPORT == 'Yes' \
-a \
$BITCOIN_KIT_EXTERNAL_ROUTER_IP != $BITCOIN_KIT_REAL_PUBLIC_IP \
] && BITCOIN_KIT_POSSIBLE_INCOMING_CONNECTIONS='No'
[ $BITCOIN_KIT_BEHIND_ROUTER == 'Yes' \
-a \
$BITCOIN_KIT_UPNP_SUPPORT == 'No' \
] && { \
BITCOIN_KIT_POSSIBLE_INCOMING_CONNECTIONS="Maybe"; \
BITCOIN_KIT_NOTICES=$BITCOIN_KIT_NOTICES$'* Incoming connections may be available\n if external IP of router is '$BITCOIN_KIT_REAL_PUBLIC_IP$'\n and you can configure it for port forwarding to '$BITCOIN_KIT_LOCAL_IP$'\n'; \
BITCOIN_KIT_SHOULD_CONFIGURE_ROUTER_PORT_FORWARDING='Maybe'; \
}
{
echo "
Summary table:
UPnP support at router ............................: $BITCOIN_KIT_UPNP_SUPPORT
Local IP address ..................................: $BITCOIN_KIT_LOCAL_IP
Real public IP address ............................: $BITCOIN_KIT_REAL_PUBLIC_IP
External router IP address ........................: $BITCOIN_KIT_EXTERNAL_ROUTER_IP
To be behind router ...............................: $BITCOIN_KIT_BEHIND_ROUTER
Possible incoming connections .....................: $BITCOIN_KIT_POSSIBLE_INCOMING_CONNECTIONS
Should you configure router for port forwarding? ..: $BITCOIN_KIT_SHOULD_CONFIGURE_ROUTER_PORT_FORWARDING
Recomendations:
$BITCOIN_KIT_NOTICES"
} > $3
cat $3
# makefile variables
{
echo "\
BITCOIN_KIT_UPNP_SUPPORT := $BITCOIN_KIT_UPNP_SUPPORT
BITCOIN_KIT_LOCAL_IP := $BITCOIN_KIT_LOCAL_IP
BITCOIN_KIT_REAL_PUBLIC_IP := $BITCOIN_KIT_REAL_PUBLIC_IP
BITCOIN_KIT_EXTERNAL_ROUTER_IP := $BITCOIN_KIT_EXTERNAL_ROUTER_IP
BITCOIN_KIT_BEHIND_ROUTER := $BITCOIN_KIT_BEHIND_ROUTER
BITCOIN_KIT_POSSIBLE_INCOMING_CONNECTIONS := $BITCOIN_KIT_POSSIBLE_INCOMING_CONNECTIONS
BITCOIN_KIT_SHOULD_CONFIGURE_ROUTER_PORT_FORWARDING := $BITCOIN_KIT_SHOULD_CONFIGURE_ROUTER_PORT_FORWARDING\
"
if [ $BITCOIN_KIT_POSSIBLE_INCOMING_CONNECTIONS == 'Yes' ]; then
echo "\
BITCOIN_KIT_LND_CONFIG_EXTERNALIP_MAINNET := externalip=$BITCOIN_KIT_REAL_PUBLIC_IP:9735\\n
BITCOIN_KIT_LND_CONFIG_EXTERNALIP_TESTNET := externalip=$BITCOIN_KIT_REAL_PUBLIC_IP:9736\\n
BITCOIN_KIT_BITCOIND_CONFIG_EXTERNALIP_MAINNET := externalip=$BITCOIN_KIT_REAL_PUBLIC_IP\\n
BITCOIN_KIT_BITCOIND_CONFIG_EXTERNALIP_TESTNET := externalip=$BITCOIN_KIT_REAL_PUBLIC_IP\\n\
"
elif [ $BITCOIN_KIT_POSSIBLE_INCOMING_CONNECTIONS == 'Maybe' ]; then
echo "\
BITCOIN_KIT_LND_CONFIG_EXTERNALIP_MAINNET := \\\\\\# You need configure router for port forwarding\\nexternalip=$BITCOIN_KIT_REAL_PUBLIC_IP:9735\\n
BITCOIN_KIT_LND_CONFIG_EXTERNALIP_TESTNET := \\\\\\# You need configure router for port forwarding\\nexternalip=$BITCOIN_KIT_REAL_PUBLIC_IP:9736\\n
BITCOIN_KIT_BITCOIND_CONFIG_EXTERNALIP_MAINNET := \\\\\\# You need configure router for port forwarding\\nexternalip=$BITCOIN_KIT_REAL_PUBLIC_IP\\n
BITCOIN_KIT_BITCOIND_CONFIG_EXTERNALIP_TESTNET := \\\\\\# You need configure router for port forwarding\\nexternalip=$BITCOIN_KIT_REAL_PUBLIC_IP\\n\
"
else
echo "\
BITCOIN_KIT_LND_CONFIG_EXTERNALIP_MAINNET :=
BITCOIN_KIT_LND_CONFIG_EXTERNALIP_TESTNET :=
BITCOIN_KIT_BITCOIND_CONFIG_EXTERNALIP_MAINNET :=
BITCOIN_KIT_BITCOIND_CONFIG_EXTERNALIP_TESTNET :=\
"
fi
} > $1
# bash environments, now it's not used, may be removed
{
echo "\
export BITCOIN_KIT_UPNP_SUPPORT=\"$BITCOIN_KIT_UPNP_SUPPORT\"
export BITCOIN_KIT_LOCAL_IP=\"$BITCOIN_KIT_LOCAL_IP\"
export BITCOIN_KIT_REAL_PUBLIC_IP=\"$BITCOIN_KIT_REAL_PUBLIC_IP\"
export BITCOIN_KIT_EXTERNAL_ROUTER_IP=\"$BITCOIN_KIT_EXTERNAL_ROUTER_IP\"
export BITCOIN_KIT_BEHIND_ROUTER=\"$BITCOIN_KIT_BEHIND_ROUTER\"
export BITCOIN_KIT_POSSIBLE_INCOMING_CONNECTIONS=\"$BITCOIN_KIT_POSSIBLE_INCOMING_CONNECTIONS\"
export BITCOIN_KIT_SHOULD_CONFIGURE_ROUTER_PORT_FORWARDING=\"$BITCOIN_KIT_SHOULD_CONFIGURE_ROUTER_PORT_FORWARDING\"\
"
if [ $BITCOIN_KIT_POSSIBLE_INCOMING_CONNECTIONS == 'Yes' ]; then
echo "\
export BITCOIN_KIT_LND_CONFIG_EXTERNALIP_MAINNET=\"externalip=$BITCOIN_KIT_REAL_PUBLIC_IP:9735\\n\"
export BITCOIN_KIT_LND_CONFIG_EXTERNALIP_TESTNET=\"externalip=$BITCOIN_KIT_REAL_PUBLIC_IP:9736\\n\"
export BITCOIN_KIT_BITCOIND_CONFIG_EXTERNALIP_MAINNET=\"externalip=$BITCOIN_KIT_REAL_PUBLIC_IP\\n\"
export BITCOIN_KIT_BITCOIND_CONFIG_EXTERNALIP_TESTNET=\"externalip=$BITCOIN_KIT_REAL_PUBLIC_IP\\n\"\
"
elif [ $BITCOIN_KIT_POSSIBLE_INCOMING_CONNECTIONS == 'Maybe' ]; then
echo "\
export BITCOIN_KIT_LND_CONFIG_EXTERNALIP_MAINNET=\"\\# You need configure router for port forwarding\\nexternalip=$BITCOIN_KIT_REAL_PUBLIC_IP:9735\\n\"
export BITCOIN_KIT_LND_CONFIG_EXTERNALIP_TESTNET=\"\\# You need configure router for port forwarding\\nexternalip=$BITCOIN_KIT_REAL_PUBLIC_IP:9736\\n\"
export BITCOIN_KIT_BITCOIND_CONFIG_EXTERNALIP_MAINNET=\"\\# You need configure router for port forwarding\\nexternalip=$BITCOIN_KIT_REAL_PUBLIC_IP\\n\"
export BITCOIN_KIT_BITCOIND_CONFIG_EXTERNALIP_TESTNET=\"\\# You need configure router for port forwarding\\nexternalip=$BITCOIN_KIT_REAL_PUBLIC_IP\\n\"\
"
else
echo "\
export BITCOIN_KIT_LND_CONFIG_EXTERNALIP_MAINNET=
export BITCOIN_KIT_LND_CONFIG_EXTERNALIP_TESTNET=
export BITCOIN_KIT_BITCOIND_CONFIG_EXTERNALIP_MAINNET=
export BITCOIN_KIT_BITCOIND_CONFIG_EXTERNALIP_TESTNET=\
"
fi
} > $2
} >&2