ipv4-ipv6.sh 6.0 KB

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