jay's blog
Macos自动启动v2ray

mac使用的脚本

自动脚本/Users/myname/Library/LaunchAgents/personal.myname.v2ray.plist

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>Label</key>
    <string>personal.myname.v2ray</string>
    <key>ProgramArguments</key>
    <array>
        <string>/opt/apps/v2ray/v2ray</string>
        <string>-c</string>
         <string>/opt/apps/v2ray/config.json</string>
    </array>
    <key>KeepAlive</key>
    <true/>
    <key>RunAtLoad</key>
    <true/>
</dict>
</plist>

加载脚本

launchctl unload /Users/myname/Library/LaunchAgents/personal.myname.v2ray.plist ; launchctl load /Users/myname/Library/LaunchAgents/personal.myname.v2ray.plist;

最优ip 推荐

https://www.youtube.com/watch?v=qFPiDeFanlA&ab_channel=%E7%A7%91%E6%8A%80%E8%87%AA%E4%B9%A0%E5%AE%A4
wz.weishao2023.dk.eu.org
wz.weishao2023.uk.eu.org
cloudflare.cfgo.cc
086181.xyz
stock.hostmonit.com
cdn.anycast.eu.org


172.64.32.1/24 (推荐移动,走香港)
104.28.14.0/24 (推荐移动,走新加坡)
104.23.240.0-104.23.243.254 (推荐联通、移动,线路未知)
108.162.236.1/24 (推荐联通,走美国)
104.20.157.0/24 (推荐联通,走日本)(gz可用)
104.16.160.1/24 (推荐电信,走洛杉矶)
172.64.0.0/24 (推荐电信,走旧金山)
172.64.32.* (走欧洲)
来源:https://cloud.tencent.com/developer/article/1675133

cf ip: https://www.cloudflare.com/zh-cn/ips/
188.114.96.0/20  联通快
104.20.157.0/24  联通快

fping -c 210 -s 198.41.212.86 188.114.96.12 104.20.157.254
fping -c 110 -s -g 104.20.157.0/24

IP CIDR换算:https://zh.rakko.tools/tools/27/

cf ip: https://www.cloudflare.com/ips/

最优ip查找(不推荐)

better-cloudflare-ip用来获取比较快的ip

echo "172.67.143.111 service.udpfile.com" >> /etc/hosts

中间转发

// Config file of V2Ray. This file follows standard JSON format, with comments support.
// Uncomment entries below to satisfy your needs. Also read our manual for more detail at
// https://www.v2fly.org/
{
  "log": {
    // By default, V2Ray writes access log to stdout.
    // "access": "/path/to/access/log/file",

    // By default, V2Ray write error log to stdout.
    // "error": "/path/to/error/log/file",
        "access": "/var/log/v2ray/access.log",
        "error": "/var/log/v2ray/error.log",
    // Log level, one of "debug", "info", "warning", "error", "none"
    "loglevel": "debug"
  },
  // List of inbound proxy configurations.
  "inbounds": [{
    // Port to listen on. You may need root access if the value is less than 1024.
    "port": 21080,

    // IP address to listen on. Change to "0.0.0.0" to listen on all network interfaces.
    "listen": "0.0.0.0",

    // Tag of the inbound proxy. May be used for routing.
    "tag": "vmess-in",

    // Protocol name of inbound proxy.
    "protocol": "vmess",

    // Settings of the protocol. Varies based on protocol.
    "settings": {
        "clients": [
          {
          "id":"client-i",
          "alterId":1
          }
        ]
    },

    "streamSettings": {
        "sockopt": {
          "tproxy": "tproxy"
        }
      },

    // Enable sniffing on TCP connection.
    "sniffing": {
      "enabled": true,
      // Target domain will be overriden to the one carried by the connection, if the connection is HTTP or HTTPS.
      "destOverride": ["http", "tls"]
    }
  }],
  // List of outbound proxy configurations.
  "outbounds": [

    {
      "tag": "proxy",
      "protocol": "vmess",
      "settings": {
        "vnext": [
          {
            "address": "www.mydomain.com",
            "port": 443,
            "users": [
              {
                "id": "client-id",
                "alterId": 1,
                "email": "[email protected]",
                "security": "auto"
              }
            ]
          }
        ],
        "servers": null,
        "response": null
      },
      "streamSettings": {
        "network": "ws",
        "security": "tls",
        "tlsSettings": {
          "allowInsecure": true,
          "serverName": null
        },
        "tcpSettings": null,
        "kcpSettings": null,
        "wsSettings": {
          "connectionReuse": true,
          "path": "/e1df4d60/",
          "headers": null
        },
        "httpSettings": null,
        "quicSettings": null
      },
      "mux": {
        "enabled": true,
        "concurrency": 8
      }
    },
    {
      "tag": "direct",
      "protocol": "freedom",
      "settings": {
        "vnext": null,
        "servers": null,
        "response": null
      },
      "streamSettings": null,
      "mux": null
    },
    {
      "tag": "block",
      "protocol": "blackhole",
      "settings": {
        "vnext": null,
        "servers": null,
        "response": {
          "type": "http"
        }
      },
      "streamSettings": null,
      "mux": null
    }

  ],

  // Transport is for global transport settings. If you have multiple transports with same settings
  // (say mKCP), you may put it here, instead of in each individual inbound/outbounds.
  //"transport": {},

  // Routing controls how traffic from inbounds are sent to outbounds.
  "routing": {
    "domainStrategy": "IPOnDemand",
    "rules":[
      {
        // Blocks access to private IPs. Remove this if you want to access your router.
        "type": "field",
        "ip": ["geoip:private"],
        "outboundTag": "blocked"
      },
      {
        // Blocks major ads.
        "type": "field",
        "domain": ["geosite:category-ads"],
        "outboundTag": "blocked"
      }
    ]
  },

  // Dns settings for domain resolution.
  "dns": {
    // Static hosts, similar to hosts file.
    "hosts": {
      // Match v2fly.org to another domain on CloudFlare. This domain will be used when querying IPs for v2fly.org.
      "domain:v2fly.org": "www.vicemc.net",

      // The following settings help to eliminate DNS poisoning in mainland China.
      // It is safe to comment these out if this is not the case for you.
      "domain:github.io": "pages.github.com",
      "domain:wikipedia.org": "www.wikimedia.org",
      "domain:shadowsocks.org": "electronicsrealm.com"
    },
    "servers": [
      "8.8.8.8",
      {
        "address": "114.114.114.114",
        "port": 53,
        // List of domains that use this DNS first.
        "domains": [
          "geosite:cn"
        ]
      },
      "8.8.4.4",
      "localhost"
    ]
  },

  // Policy controls some internal behavior of how V2Ray handles connections.
  // It may be on connection level by user levels in 'levels', or global settings in 'system.'
  "policy": {
    // Connection policys by user levels
    "levels": {
      "0": {
        "uplinkOnly": 0,
        "downlinkOnly": 0
      }
    },
    "system": {
      "statsInboundUplink": false,
      "statsInboundDownlink": false,
      "statsOutboundUplink": false,
      "statsOutboundDownlink": false
    }
  },

  // Stats enables internal stats counter.
  // This setting can be used together with Policy and Api.
  //"stats":{},

  // Api enables gRPC APIs for external programs to communicate with V2Ray instance.
  //"api": {
    //"tag": "api",
    //"services": [
    //  "HandlerService",
    //  "LoggerService",
    //  "StatsService"
    //]
  //},

  // You may add other entries to the configuration, but they will not be recognized by V2Ray.
  "other": {}
}

sed教程 sed -i 's/n/\n/g' result_ip.txt

fping -c 10 -Q 10 -f result_ip.txt > result_ip_ping.txt

awk简明教程 awk -F '/' '{if($8*1 < 140){print $0}}' result_ip_ping.txt

grep '优选的IP地址为' l.txt|sed 's/优选的IP地址为//g'|sed 's/ - /\n/g'|sed 's/ //g'|fping -c 100 -Q 10 -s

Macos自动更新IP

#!/usr/bin/env sh

 rs=`/opt/homebrew/bin/fping -c 100 -q -s 104.27.200.69 172.67.60.78 104.25.140.153 104.27.192.65 172.67.62.214 104.27.207.5 172.67.54.193 104.22.66.8 104.27.197.63 104.27.192.86 172.67.58.91 103.21.244.222 104.28.14.229 104.28.14.247 104.27.    192.65 188.114.96.123 104.16.160.252 188.114.97.171 104.20.157.254 188.114.96.24 2>&1`

 # 最优IP
 ip=""
 # 丢失率
 idx=0

 # 取丢失率小于50%的
 while [ "$idx" -lt 30  ]
 do
     ip=$(echo "$rs"|grep 'xmt/rcv/%loss'|grep "/${idx}%"|awk '{split($8,arr,"/"); print arr[2],$1|"sort -k 1" }'|head -n 1|awk '{print $2}')
     if [ "$ip" != "" ]; then
         break
     fi
     idx=$(($idx + 1))
 done

 # 没有取到ip,直接退出
 if [[ "$ip" == "" ]];
 then
     echo "ip 为空"
     exit 0
 fi

 origin=$(grep -E '^\d+.*qqopp.gq' /etc/hosts)
 if [[ "$ip" != "" && "$origin" != "" ]]; then
     sed -i.backup -e "s/$origin/$ip  qqopp.gq  www.qqopp.gq  blog.qqopp.gq  ylfys.ga  www.ylfys.ga/" /etc/hosts
     #pid=`ps -ef|grep v2ray|grep -v 'grep'|awk '{pint $2}'`
     #echo $pid
     #set +m
     #kill $pid
     #sleep 1
     sudo su - qqq -c "launchctl bootout gui/503/personal.qqq.v2ray"
     sleep 0.5
     sudo su - qqq -c "launchctl load /Users/qqq/Library/LaunchAgents/personal.qqq.v2ray.plist"
     echo "success,ip:$ip"
 else
     echo "failed,ip:${ip}, ping值:${rs}"
 fi

用GO来探测

package main

import (
	"crypto/tls"
	"io/ioutil"
	"net"
	"net/http"
	"os"
	"strings"
	"sync/atomic"
	"time"
)

var client = &http.Client{
	Timeout: time.Millisecond * 300,
	CheckRedirect: func(req *http.Request, via []*http.Request) error {
		return http.ErrUseLastResponse
	},
	Transport: &http.Transport{
		TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
	}}

func main() {
	var cidrs = []string{
		//"103.21.244.0/22",
		//"103.22.200.0/22",
		//"103.31.4.0/22",
		"104.16.0.0/13",
		"104.24.0.0/14",
		"108.162.192.0/18",
		"131.0.72.0/22",
		"141.101.64.0/18",
		"162.158.0.0/15",
		"172.64.0.0/13",
		"173.245.48.0/20",
		"188.114.96.0/20",
		"190.93.240.0/20",
		"197.234.240.0/22",
		"198.41.128.0/17"}

	var ips []string
	for _, cidrString := range cidrs {
		cidr, ipNet, err := net.ParseCIDR(cidrString)
		if nil != err {
			println(err.Error())
			return
		}
		for ip := cidr.Mask(ipNet.Mask); ipNet.Contains(ip); inc(ip) {
			if ip[3] != 0 {
				ips = append(ips, ip.String())
			}
		}
	}
	addr := new(int32)

	//println(strings.Join(ips, ","), len(ips))
	f, err := os.OpenFile("test.sh", os.O_APPEND|os.O_WRONLY|os.O_CREATE, 0755)
	if err != nil {
		panic(err)
	}

	defer f.Close()
	c := make(chan string)
	for i := 0; i < 100; i++ {
		go ping(c)
	}
	go func() {
		for {
			time.Sleep(10 * time.Second)
			println(*addr)
		}
	}()
	for _, ipStr := range ips {
		c <- ipStr
		atomic.AddInt32(addr, 1)
	}
}
func ping(c chan string) {
	for {
		ipStr := <-c
		resp, err := client.Get("http://" + ipStr + "/cdn-cgi/trace")
		if nil == err {
			if all, err := ioutil.ReadAll(resp.Body); nil == err {
				arr := strings.Split(string(all), "\n")
				for _, l := range arr {
					if strings.HasPrefix(l, "h=") {
						print(strings.Split(l, "=")[1])
					}
					if strings.HasPrefix(l, "colo=") {
						println("\t", strings.Split(l, "colo=")[1])
					}

				}
			}
			//if _, err = f.WriteString("curl --connect-timeout 0.5 -m 1 http://" + ipStr + "/cdn-cgi/trace  | grep \"h=\\|colo=\" >> colo.log\n"); err != nil {
			//	panic(err)
			//}
		}
	}
}

func inc(ip net.IP) {
	for j := len(ip) - 1; j >= 0; j-- {
		ip[j] += 11
		if ip[j] > 0 {
			break
		}
	}
}

探测结果

3400
6700
10000
13300
16600
20000
23300
26600
29900
104.16.117.80    LAX
104.16.117.179   LAX
104.16.117.168   LAX
104.16.117.245   LAX
104.16.117.91    LAX
104.16.117.157   LAX
104.16.117.190   LAX
33200
36500
39819
43119
46500
49800
53100
56409
59720
63027
66401
69701
73017
76320
79625
83001
86302
89618
92921
96226
99601
102901
106219
109522
112852
116202
119502
122819
126122
129452
132802
136102
139419
142719
146022
149359
152702
156009
159319
162623
165953
169302
172609
175919
179223
182553
185902
189209
192509
195819
199153
202502
205802
209109
172.64.228.66    NRT
172.64.228.22    NRT
172.64.228.44    NRT
172.64.228.33    NRT
172.64.228.220   NRT
172.64.228.11    NRT
172.64.228.121   NRT
172.64.228.198   NRT
172.64.228.165   NRT
172.64.228.187   NRT
172.64.228.231   NRT
172.64.228.132   NRT
172.64.228.242   NRT
172.64.228.30    NRT
172.64.228.176   NRT
172.64.228.55    NRT
172.64.228.77    NRT
172.64.228.209   NRT
172.64.228.154   NRT
172.64.228.99    NRT
172.64.228.253   NRT
172.64.228.88    NRT
172.64.228.8     NRT
172.64.228.143   NRT
172.64.228.110   NRT
172.64.228.19    NRT
172.64.228.41    NRT
172.64.228.107   NRT
172.64.228.63    NRT
172.64.228.74    NRT
172.64.228.52    NRT
172.64.228.85    NRT
172.64.228.118   NRT
172.64.228.96    NRT
172.64.228.129   NRT
172.64.228.140   NRT
172.64.228.217   NRT
172.64.228.206   NRT
172.64.228.228   NRT
172.64.228.162   NRT
172.64.228.173   NRT
172.64.228.151   NRT
172.64.228.195   NRT
172.64.228.184   NRT
172.64.228.239   NRT
172.64.228.49    NRT
172.64.228.38    NRT
172.64.228.236   NRT
172.64.228.13    NRT
172.64.228.93    NRT
172.64.228.225   NRT
172.64.228.104   NRT
172.64.228.82    NRT
172.64.228.16    NRT
172.64.228.192   NRT
172.64.228.250   NRT
172.64.228.203   NRT
172.64.228.159   NRT
172.64.228.5     NRT
172.64.228.60    NRT
172.64.228.170   NRT
172.64.228.247   NRT
172.64.228.214   NRT
172.64.228.137   NRT
172.64.228.126   NRT
172.64.228.115   NRT
172.64.228.181   NRT
172.64.228.2     NRT
172.64.228.24    NRT
172.64.228.90    NRT
172.64.228.46    NRT
172.64.228.197   NRT
172.64.228.145   NRT
172.64.228.43    NRT
172.64.228.57    NRT
172.64.228.167   NRT
172.64.228.87    NRT
172.64.228.68    NRT
172.64.228.112   NRT
172.64.228.164   NRT
172.64.228.186   NRT
172.64.228.153   NRT
172.64.228.244   NRT
172.64.228.101   NRT
172.64.228.142   NRT
172.64.228.10    NRT
172.64.228.32    NRT
172.64.228.35    NRT
172.64.228.7     NRT
172.64.228.123   NRT
172.64.228.40    NRT
172.64.228.73    NRT
172.64.228.156   NRT
172.64.228.120   NRT
172.64.228.18    NRT
172.64.228.222   NRT
172.64.228.200   NRT
172.64.228.79    NRT
172.64.228.29    NRT
172.64.228.65    NRT
172.64.228.211   NRT
172.64.228.21    NRT
172.64.228.76    NRT
172.64.228.230   NRT
172.64.228.233   NRT
172.64.228.183   NRT
172.64.228.134   NRT
172.64.228.128   NRT
172.64.228.84    NRT
172.64.228.208   NRT
172.64.228.175   NRT
172.64.228.109   NRT
172.64.228.106   NRT
172.64.228.241   NRT
172.64.228.98    NRT
172.64.228.131   NRT
172.64.228.54    NRT
172.64.228.161   NRT
172.64.228.172   NRT
172.64.228.117   NRT
172.64.228.139   NRT
172.64.228.51    NRT
172.64.228.219   NRT
172.64.228.150   NRT
172.64.228.205   NRT
172.64.228.62    NRT
172.64.228.95    NRT
172.64.228.4     NRT
172.64.228.26    NRT
172.64.228.15    NRT
172.64.228.216   NRT
172.64.228.238   NRT
172.64.228.227   NRT
172.64.228.249   NRT
172.64.228.48    NRT
172.64.228.37    NRT
172.64.228.136   NRT
172.64.228.81    NRT
172.64.228.202   NRT
172.64.228.158   NRT
172.64.228.125   NRT
172.64.228.92    NRT
172.64.228.70    NRT
172.64.228.103   NRT
172.64.228.59    NRT
172.64.228.147   NRT
172.64.228.169   NRT
172.64.228.45    NRT
172.64.228.1     NRT
172.64.228.23    NRT
172.64.228.213   NRT
172.64.228.34    NRT
172.64.228.235   NRT
172.64.228.12    NRT
172.64.228.78    NRT
172.64.228.133   NRT
172.64.228.89    NRT
172.64.228.100   NRT
172.64.228.122   NRT
172.64.228.188   NRT
172.64.228.155   NRT
172.64.228.199   NRT
172.64.228.166   NRT
172.64.228.177   NRT
172.64.228.243   NRT
172.64.228.9     NRT
172.64.228.20    NRT
172.64.228.111   NRT
172.64.228.254   NRT
172.64.228.31    NRT
172.64.228.42    NRT
172.64.228.53    NRT
172.64.228.97    NRT
172.64.228.207   NRT
172.64.228.86    NRT
172.64.228.75    NRT
172.64.228.39    NRT
172.64.228.229   NRT
172.64.228.240   NRT
172.64.228.251   NRT
172.64.228.72    NRT
172.64.228.130   NRT
172.64.228.185   NRT
172.64.228.94    NRT
172.64.228.116   NRT
172.64.228.105   NRT
172.64.228.138   NRT
172.64.228.61    NRT
172.64.228.152   NRT
172.64.228.171   NRT
172.64.228.50    NRT
172.64.228.182   NRT
172.64.228.174   NRT
172.64.228.6     NRT
172.64.228.193   NRT
172.64.228.119   NRT
172.64.228.163   NRT
172.64.228.83    NRT
172.64.228.204   NRT
172.64.228.226   NRT
172.64.228.196   NRT
172.64.228.28    NRT
172.64.228.160   NRT
172.64.228.237   NRT
172.64.228.14    NRT
172.64.228.248   NRT
172.64.228.36    NRT
172.64.228.3     NRT
172.64.228.25    NRT
172.64.228.47    NRT
172.64.228.69    NRT
172.64.228.58    NRT
172.64.228.102   NRT
172.64.228.80    NRT
172.64.228.124   NRT
172.64.228.168   NRT
172.64.228.190   NRT
172.64.228.179   NRT
172.64.228.223   NRT
172.64.228.201   NRT
172.64.228.146   NRT
172.64.228.157   NRT
172.64.228.135   NRT
172.64.228.234   NRT
172.64.228.212   NRT
212514
215826
219129
222457
225765
229100
232417
235729
239036
242357
245700
249006
252320
255629
258940
262248
265606
268918

https://www.rfi.fr/cn/%E4%B8%AD%E5%9B%BD/20220203-%E7%BD%91%E7%BB%9C%E6%96%87%E6%91%98-%E5%AE%A2%E8%A7%82%E8%AF%84%E4%BB%B7%E4%B9%A0%E8%BF%91%E5%B9%B3

域名

  • 申请域名时要将浏览器语言设置为en
  • 绑定后要将nginx和hugo的域名替换为新域名
  • 申请证书
1. 签发证书
2. 安装证书
3. 替换nginx地址
  • cloudflare中增加域名。要将ssl设置为完全(严格),否则会有一直重定向问题

最后修改于 2021-08-15