ipv4-ipv6.sh 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  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 48 ]; then
  52. IP6PREFIX=$(echo $IP6 | cut -f1-3 -d':')
  53. fi
  54. if [ $IP6PREFIXLEN -eq 64 ]; then
  55. IP6PREFIX=$(echo $IP6 | cut -f1-4 -d':')
  56. fi
  57. if [ $IP6PREFIXLEN -eq 112 ]; then
  58. IP6PREFIX=$(echo $IP6 | rev | cut -f2- -d':' | rev)
  59. fi
  60. eecho "IPv6 PrefixLen: $IP6PREFIXLEN --> Prefix: $IP6PREFIX"
  61. while [ ! -n "$ETHNAME" ]; do
  62. eecho "Please input network interface name: (eth0 as default)"
  63. read ETHNAME
  64. if [[ $ETHNAME == "" ]]; then
  65. ETHNAME="eth0"
  66. fi
  67. done
  68. while [ ! -n "$PROXYUSER" ]; do
  69. eecho "Please input username for proxy: (smile as default)"
  70. read PROXYUSER
  71. if [[ $PROXYUSER == "" ]]; then
  72. PROXYUSER="smile"
  73. fi
  74. done
  75. while [ ! -n "$PROXYPASS" ]; do
  76. eecho "Please input password for proxy: (girl as default)"
  77. read PROXYPASS
  78. if [[ $PROXYPASS == "" ]]; then
  79. PROXYPASS="girl"
  80. fi
  81. done
  82. #################### functions ####################
  83. gen_data() {
  84. array=(1 2 3 4 5 6 7 8 9 0 a b c d e f)
  85. ip64() {
  86. echo "${array[$RANDOM % 16]}${array[$RANDOM % 16]}${array[$RANDOM % 16]}${array[$RANDOM % 16]}"
  87. }
  88. seq 1 $PROXYCOUNT | while read idx; do
  89. port=$(($idx+10000))
  90. if [[ $IP6PREFIXLEN -eq 112 ]]; then
  91. suffix=$(($idx+1))
  92. suffix=$(printf '%x\n' $suffix)
  93. echo "$PROXYUSER/$PROXYPASS/$IP4/$port/$IP6PREFIX:$suffix"
  94. fi
  95. if [[ $IP6PREFIXLEN -eq 64 ]]; then
  96. echo "$PROXYUSER/$PROXYPASS/$IP4/$port/$IP6PREFIX:$(ip64):$(ip64):$(ip64):$(ip64)"
  97. fi
  98. if [[ $IP6PREFIXLEN -eq 48 ]]; then
  99. echo "$PROXYUSER/$PROXYPASS/$IP4/$port/$IP6PREFIX:$(ip64):$(ip64):$(ip64):$(ip64):$(ip64)"
  100. fi
  101. done
  102. }
  103. gen_iptables() {
  104. cat <<EOF
  105. $(awk -F "/" '{print "iptables -I INPUT -p tcp --dport " $4 " -m state --state NEW -j ACCEPT"}' ${WORKDATA})
  106. EOF
  107. }
  108. gen_ifconfig() {
  109. cat <<EOF
  110. $(awk -v ETHNAME="$ETHNAME" -v IP6PREFIXLEN="$IP6PREFIXLEN" -F "/" '{print "ifconfig " ETHNAME " inet6 add " $5 "/" IP6PREFIXLEN}' ${WORKDATA})
  111. EOF
  112. }
  113. gen_static() {
  114. NETWORK_FILE="/etc/sysconfig/network-scripts/ifcfg-$ETHNAME"
  115. cat <<EOF
  116. 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
  117. EOF
  118. }
  119. gen_proxy_file() {
  120. cat <<EOF
  121. $(awk -F "/" '{print $3 ":" $4 ":" $1 ":" $2 }' ${WORKDATA})
  122. EOF
  123. }
  124. install_3proxy() {
  125. eecho "Installing 3proxy ..."
  126. git clone https://github.com/MohistAttack/3proxy
  127. cd 3proxy
  128. ln -s Makefile.Linux Makefile
  129. make
  130. make install
  131. cd ..
  132. }
  133. # https://3proxy.ru/doc/man3/3proxy.cfg.3.html
  134. # https://github.com/3proxy/3proxy/blob/master/scripts/3proxy.cfg
  135. # log /logs/3proxy-%y%m%d.log D
  136. # rotate 30
  137. # if need , please add before cmd: counter /count/3proxy.3cf
  138. gen_3proxy() {
  139. cat <<EOF
  140. nscache 65536
  141. nserver 8.8.8.8
  142. nserver 8.8.4.4
  143. config /conf/3proxy.cfg
  144. monitor /conf/3proxy.cfg
  145. counter /count/3proxy.3cf
  146. include /conf/counters
  147. include /conf/bandlimiters
  148. users $(awk -F "/" '{print $1 ":CL:" $2}' ${WORKDATA} | uniq | sed -z 's/\n/ /g')
  149. flush
  150. $(awk -F "/" '{print "auth strong\n" \
  151. "allow " $1 "\n" \
  152. "proxy -6 -n -a -p" $4 " -i" $3 " -e"$5"\n" \
  153. "flush\n"}' ${WORKDATA})
  154. EOF
  155. }
  156. ####################
  157. eecho "Installing apps ... (yum)"
  158. yum -y install gcc net-tools bsdtar zip git make
  159. ###################
  160. install_3proxy
  161. # ###################
  162. WORKDIR="/usr/local/3proxy/installer"
  163. WORKDATA="${WORKDIR}/data.txt"
  164. mkdir -p $WORKDIR
  165. eecho "Working folder = $WORKDIR"
  166. gen_data >$WORKDATA
  167. gen_3proxy >/usr/local/3proxy/conf/3proxy.cfg
  168. gen_iptables >$WORKDIR/boot_iptables.sh
  169. gen_ifconfig >$WORKDIR/boot_ifconfig.sh
  170. gen_static >$WORKDIR/boot_static.sh
  171. BOOTRCFILE="$WORKDIR/boot_rc.sh"
  172. REGISTER_LOGIC="bash ${WORKDIR}/boot_ifconfig.sh"
  173. if [[ $STATIC == "yes" ]]; then
  174. REGISTER_LOGIC="bash ${WORKDIR}/boot_static.sh && systemctl restart network"
  175. fi
  176. cat >$BOOTRCFILE <<EOF
  177. bash ${WORKDIR}/boot_iptables.sh
  178. ${REGISTER_LOGIC}
  179. systemctl restart 3proxy
  180. # systemctl stop firewalld
  181. # systemctl disable firewalld
  182. # systemctl disable firewalld.service
  183. EOF
  184. chmod +x ${WORKDIR}/boot_*.sh
  185. # change ulimit for too many open files
  186. grep -qxF '* soft nofile 1024000' /etc/security/limits.conf || cat >>/etc/security/limits.conf <<EOF
  187. * soft nofile 1024000
  188. * hard nofile 1024000
  189. EOF
  190. # qxF match whole line
  191. grep -qxF "bash $BOOTRCFILE" /etc/rc.local || cat >>/etc/rc.local <<EOF
  192. bash $BOOTRCFILE
  193. EOF
  194. chmod +x /etc/rc.local
  195. bash /etc/rc.local
  196. PROXYFILE=proxy.txt
  197. gen_proxy_file >$PROXYFILE
  198. eecho "Done with $PROXYFILE"
  199. zip --password $PROXYPASS proxy.zip $PROXYFILE
  200. URL=$(curl -s --upload-file proxy.zip http://transfer.sh/smile.zip)
  201. eecho "Proxy is ready! Format IP:PORT:LOGIN:PASS"
  202. eecho "Download zip archive from: ${URL}"
  203. eecho "Password: ${PROXYPASS}"