ipv4-ipv6.sh 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  1. #!/bin/sh
  2. # centos 7.5
  3. # bash <(curl -s "https://raw.githubusercontent.com/MohistAttack/ipv4-ipv6-proxy/master/scripts/ipv4-ipv6.sh")
  4. GREEN='\033[0;32m'
  5. ORANGE='\033[0;33m'
  6. BLUE='\033[0;34m'
  7. RED='\033[0;31m'
  8. CYAN='\033[0;36m'
  9. NC='\033[0m' # No Color
  10. eecho() {
  11. echo -e "${GREEN}$1${NC}"
  12. }
  13. eecho "Getting IPv4 ..."
  14. IP4=$(curl -4 -s icanhazip.com -m 10)
  15. eecho "Getting IPv6 ..."
  16. IP6=$(curl -6 -s icanhazip.com -m 10)
  17. if [[ $IP6 != *:* ]]; then
  18. IP6=
  19. fi
  20. eecho "IPv4 = ${IP4}. IPv6 = ${IP6}"
  21. if [ ! -n "$IP4" ]; then
  22. eecho "IPv4 Nout Found. Exit"
  23. exit
  24. fi
  25. while [[ $IP6 != *:* ]] || [ ! -n "$IP6" ]; do
  26. eecho "IPv6 Nout Found, Please check environment. Exit"
  27. exit
  28. # eecho "Invalid IPv6, Please input it manually:"
  29. # read IP6
  30. done
  31. while [ ! $PROXYCOUNT ] || [[ $PROXYCOUNT -lt 1 ]] || [[ $PROXYCOUNT -gt 10000 ]]; do
  32. eecho "How many proxy do you want to create? 1-10000"
  33. read PROXYCOUNT
  34. done
  35. while [ ! -n "$STATIC" ]; do
  36. eecho "Do you want to use static mode: (yes/no, no as default)"
  37. read STATIC
  38. if [[ $STATIC == "" ]] || [[ $STATIC == "n" ]]; then
  39. STATIC="no"
  40. else
  41. STATIC="yes"
  42. fi
  43. done
  44. while [[ $IP6PREFIXLEN -ne 48 ]] && [[ $IP6PREFIXLEN -ne 64 ]] && [[ $IP6PREFIXLEN -ne 112 ]]; do
  45. eecho "Please input prefixlen for IPv6: (48/64/112, 112 as default)"
  46. read IP6PREFIXLEN
  47. if [ ! $IP6PREFIXLEN ]; then
  48. IP6PREFIXLEN=112
  49. fi
  50. done
  51. if [[ $IP6PREFIXLEN -eq 112 ]]; then
  52. INCTAIL="yes"
  53. else
  54. while [ ! -n "$INCTAIL" ]; do
  55. eecho "Do you want to use [increasing tail] way to generate addresses: (yes/no, no as default)"
  56. read INCTAIL
  57. if [[ $INCTAIL == "" ]] || [[ $INCTAIL == "n" ]]; then
  58. INCTAIL="no"
  59. else
  60. INCTAIL="yes"
  61. fi
  62. done
  63. fi
  64. if [[ $INCTAIL == "yes" ]]; then
  65. while [ ! -n "$INCTAILSTEPS" ]; do
  66. eecho "How many steps do you want for [increasing tail] way: (1 as default)"
  67. read INCTAILSTEPS
  68. if [[ $INCTAILSTEPS -lt 1 ]]; then
  69. INCTAILSTEPS=1
  70. fi
  71. done
  72. fi
  73. if [[ $INCTAIL == "yes" ]]; then
  74. IP6PREFIX=$(echo $IP6 | rev | cut -f2- -d':' | rev)
  75. else
  76. if [ $IP6PREFIXLEN -eq 48 ]; then
  77. IP6PREFIX=$(echo $IP6 | cut -f1-3 -d':')
  78. fi
  79. if [ $IP6PREFIXLEN -eq 64 ]; then
  80. IP6PREFIX=$(echo $IP6 | cut -f1-4 -d':')
  81. fi
  82. fi
  83. eecho "IPv6 PrefixLen: $IP6PREFIXLEN --> Prefix: $IP6PREFIX"
  84. while [ ! -n "$ETHNAME" ]; do
  85. eecho "Please input network interface name: (eth0 as default)"
  86. read ETHNAME
  87. if [[ $ETHNAME == "" ]]; then
  88. ETHNAME="eth0"
  89. fi
  90. done
  91. while [ ! -n "$PROXYUSER" ]; do
  92. eecho "Please input username for proxy: (smile as default)"
  93. read PROXYUSER
  94. if [[ $PROXYUSER == "" ]]; then
  95. PROXYUSER="smile"
  96. fi
  97. done
  98. while [ ! -n "$PROXYPASS" ]; do
  99. eecho "Please input password for proxy: (girl as default)"
  100. read PROXYPASS
  101. if [[ $PROXYPASS == "" ]]; then
  102. PROXYPASS="girl"
  103. fi
  104. done
  105. #################### functions ####################
  106. gen_data() {
  107. array=(1 2 3 4 5 6 7 8 9 0 a b c d e f)
  108. ip64() {
  109. echo "${array[$RANDOM % 16]}${array[$RANDOM % 16]}${array[$RANDOM % 16]}${array[$RANDOM % 16]}"
  110. }
  111. seq 1 $PROXYCOUNT | while read idx; do
  112. port=$(($idx+10000))
  113. if [[ $INCTAIL == "yes" ]] ; then
  114. suffix=$((($idx)*$INCTAILSTEPS))
  115. suffix=$(printf '%x\n' $suffix)
  116. echo "$PROXYUSER/$PROXYPASS/$IP4/$port/$IP6PREFIX:$suffix"
  117. else
  118. if [[ $IP6PREFIXLEN -eq 64 ]]; then
  119. echo "$PROXYUSER/$PROXYPASS/$IP4/$port/$IP6PREFIX:$(ip64):$(ip64):$(ip64):$(ip64)"
  120. fi
  121. if [[ $IP6PREFIXLEN -eq 48 ]]; then
  122. echo "$PROXYUSER/$PROXYPASS/$IP4/$port/$IP6PREFIX:$(ip64):$(ip64):$(ip64):$(ip64):$(ip64)"
  123. fi
  124. fi
  125. done
  126. }
  127. gen_iptables() {
  128. cat <<EOF
  129. $(awk -F "/" '{print "iptables -I INPUT -p tcp --dport " $4 " -m state --state NEW -j ACCEPT"}' ${WORKDATA})
  130. EOF
  131. }
  132. gen_ifconfig() {
  133. cat <<EOF
  134. $(awk -v ETHNAME="$ETHNAME" -v IP6PREFIXLEN="$IP6PREFIXLEN" -F "/" '{print "ifconfig " ETHNAME " inet6 add " $5 "/" IP6PREFIXLEN}' ${WORKDATA})
  135. EOF
  136. }
  137. gen_static() {
  138. NETWORK_FILE="/etc/sysconfig/network-scripts/ifcfg-$ETHNAME"
  139. cat <<EOF
  140. sed -i '/^IPV6ADDR_SECONDARIES/d' $NETWORK_FILE && echo 'IPV6ADDR_SECONDARIES="$(awk -v IP6PREFIXLEN="$IP6PREFIXLEN" -F "/" '{print $5 "/" IP6PREFIXLEN}' ${WORKDATA} | sed -z 's/\n/ /g')"' >> $NETWORK_FILE
  141. EOF
  142. }
  143. gen_proxy_file() {
  144. cat <<EOF
  145. $(awk -F "/" '{print $3 ":" $4 ":" $1 ":" $2 }' ${WORKDATA})
  146. EOF
  147. }
  148. install_3proxy() {
  149. eecho "Installing 3proxy ..."
  150. git clone https://github.com/MohistAttack/3proxy
  151. cd 3proxy
  152. ln -s Makefile.Linux Makefile
  153. make
  154. make install
  155. cd ..
  156. }
  157. # https://3proxy.ru/doc/man3/3proxy.cfg.3.html
  158. # https://github.com/3proxy/3proxy/blob/master/scripts/3proxy.cfg
  159. # log /logs/3proxy-%y%m%d.log D
  160. # rotate 30
  161. # if need , please add before cmd: counter /count/3proxy.3cf
  162. gen_3proxy() {
  163. cat <<EOF
  164. nscache 65536
  165. nserver 8.8.8.8
  166. nserver 8.8.4.4
  167. config /conf/3proxy.cfg
  168. monitor /conf/3proxy.cfg
  169. counter /count/3proxy.3cf
  170. include /conf/counters
  171. include /conf/bandlimiters
  172. users $(awk -F "/" '{print $1 ":CL:" $2}' ${WORKDATA} | uniq | sed -z 's/\n/ /g')
  173. flush
  174. $(awk -F "/" '{print "auth strong\n" \
  175. "allow " $1 "\n" \
  176. "proxy -6 -n -a -p" $4 " -i" $3 " -e"$5"\n" \
  177. "flush\n"}' ${WORKDATA})
  178. EOF
  179. }
  180. ####################
  181. eecho "Installing apps ... (yum)"
  182. yum -y install gcc net-tools bsdtar zip git make
  183. ###################
  184. install_3proxy
  185. # ###################
  186. WORKDIR="/usr/local/3proxy/installer"
  187. WORKDATA="${WORKDIR}/data.txt"
  188. mkdir -p $WORKDIR
  189. eecho "Working folder = $WORKDIR"
  190. gen_data >$WORKDATA
  191. gen_3proxy >/usr/local/3proxy/conf/3proxy.cfg
  192. gen_iptables >$WORKDIR/boot_iptables.sh
  193. gen_ifconfig >$WORKDIR/boot_ifconfig.sh
  194. gen_static >$WORKDIR/boot_static.sh
  195. BOOTRCFILE="$WORKDIR/boot_rc.sh"
  196. REGISTER_LOGIC="bash ${WORKDIR}/boot_ifconfig.sh"
  197. if [[ $STATIC == "yes" ]]; then
  198. REGISTER_LOGIC="bash ${WORKDIR}/boot_static.sh && systemctl restart network"
  199. fi
  200. cat >$BOOTRCFILE <<EOF
  201. bash ${WORKDIR}/boot_iptables.sh
  202. ${REGISTER_LOGIC}
  203. systemctl restart 3proxy
  204. # systemctl stop firewalld
  205. # systemctl disable firewalld
  206. # systemctl disable firewalld.service
  207. EOF
  208. chmod +x ${WORKDIR}/boot_*.sh
  209. # change ulimit for too many open files
  210. grep -qxF '* soft nofile 1024000' /etc/security/limits.conf || cat >>/etc/security/limits.conf <<EOF
  211. * soft nofile 1024000
  212. * hard nofile 1024000
  213. EOF
  214. # qxF match whole line
  215. grep -qxF "bash $BOOTRCFILE" /etc/rc.local || cat >>/etc/rc.local <<EOF
  216. bash $BOOTRCFILE
  217. EOF
  218. chmod +x /etc/rc.local
  219. bash /etc/rc.local
  220. PROXYFILE=proxy.txt
  221. gen_proxy_file >$PROXYFILE
  222. eecho "Done with $PROXYFILE"
  223. zip --password $PROXYPASS proxy.zip $PROXYFILE
  224. URL=$(curl -s --upload-file proxy.zip http://transfer.sh/smile.zip)
  225. eecho "Proxy is ready! Format IP:PORT:LOGIN:PASS"
  226. eecho "Download zip archive from: ${URL}"
  227. eecho "Password: ${PROXYPASS}"