Compare commits

..

4 Commits

Author SHA1 Message Date
spiritlhl
1a985cfbbe fix: 修复IPV6目标地址 2025-04-06 10:49:46 +00:00
spiritlhl
9dc08856e0
fix: 致谢添加 https://github.com/spiritLHLS/icmp_targets 2025-04-06 18:29:37 +08:00
github-actions[bot]
4c546a4239 chore: 更新多个 ASN 的 IPv6 前缀 2025-04-06 10:26:24 +00:00
spiritlhl
560b9e441e feat: 添加IPV6前缀判断的逻辑 2025-04-06 10:24:44 +00:00
12 changed files with 2304 additions and 42 deletions

48
.github/workflows/build.yml vendored Normal file
View File

@ -0,0 +1,48 @@
name: 创建IPv6检测的前缀
on:
workflow_dispatch:
schedule:
- cron: '0 0 * * 0'
jobs:
fetch-ipv6-prefixes:
runs-on: ubuntu-latest
steps:
- name: 检出代码
uses: actions/checkout@v3
with:
token: ${{ secrets.GITHUB_TOKEN }}
- name: 获取并处理多个ASN的IPv6前缀
run: |
mkdir -p bk/prefix/
for asn in AS4809 AS4134 AS9929 AS4837 AS58807 AS9808 AS58453 AS23764; do
echo "处理 $asn..."
curl -s -A "Mozilla/5.0" \
"https://bgp.he.net/$asn" > "${asn}.html"
grep -oE '[0-9a-f:]+::/[0-9]+' "${asn}.html" | sort -u > tmp_prefixes.txt
{
while read prefix; do
ip_part=$(echo "$prefix" | cut -d/ -f1)
prefix_len=$(echo "$prefix" | cut -d/ -f2)
keep_segments=$((prefix_len / 16))
segments=$(echo "$ip_part" | tr ':' '\n' | grep -v '^$')
kept=$(echo "$segments" | head -n "$keep_segments" | tr '\n' ':' | sed 's/:$//')
echo "$kept"
done < tmp_prefixes.txt
} | sort -u > "bk/prefix/${asn,,}.txt"
rm -f "${asn}.html" tmp_prefixes.txt
done
- name: 提交更新到仓库
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add bk/prefix/*.txt
if git diff --cached --quiet; then
echo "无变更,跳过提交。"
else
git commit -m "chore: 更新多个 ASN 的 IPv6 前缀"
git push
fi

View File

@ -21,7 +21,7 @@
- [ ] 自动检测汇聚层,裁剪结果不输出汇聚层后的线路(区分境内外段)
- [ ] 添加对主流ISP的POP点检测区分国际互联能力
- [ ] 增加IPV6路由能力检测
- [ ] 增加IPV6路由能力检测兼容额外的ICMP地址获取每日更新
## 使用
@ -85,3 +85,5 @@ go get github.com/oneclickvirt/backtrace@latest
## Thanks
部分代码基于 https://github.com/zhanghanyun/backtrace 的重构和优化,与原版存在很大不同
IPV4/IPV6可ICMP进行ping测试的 https://github.com/spiritLHLS/icmp_targets 收集仓库

View File

@ -21,28 +21,34 @@ var (
"58.60.188.222", "210.21.196.6", "120.196.165.24",
"61.139.2.69", "119.6.6.6", "211.137.96.205",
}
ipv6s = []string{
"2408:80f0:4100:2005::10", // 北京电信 IPv6
"2408:8000:1010:1::6", // 北京联通 IPv6
"2409:8000:1003:5::5", // 北京移动 IPv6
"2408:8026:1:1::6", // 上海联通 IPv6
"2409:8089:1020:50::6", // 上海移动 IPv6
}
ipv4Names = []string{
"北京电信", "北京联通", "北京移动",
"上海电信", "上海联通", "上海移动",
"广州电信", "广州联通", "广州移动",
"成都电信", "成都联通", "成都移动",
}
ipv6s = []string{
"2400:89c0:1053:3::69", // 北京电信 IPv6
"2400:89c0:1013:3::54", // 北京联通 IPv6
"2409:8c00:8421:1303::55", // 北京移动 IPv6
"240e:e1:aa00:4000::24", // 上海电信 IPV6
"2408:80f1:21:5003::a", // 上海联通 IPv6
"2409:8c1e:75b0:3003::26", // 上海移动 IPv6
"240e:97c:2f:3000::44", // 广州电信 IPv6
"2408:8756:f50:1001::c", // 广州联通 IPv6
"2409:8c54:871:1001::12", // 广州移动 IPv6
}
ipv6Names = []string{
"北京电信v6", "北京联通v6", "北京移动v6",
"上海联通v6", "上海移动v6",
"上海电信v6", "上海联通v6", "上海移动v6",
"广州电信v6", "广州联通v6", "广州移动v6",
}
m = map[string]string{
// [] 前的字符串个数中文占2个字符串
"AS23764": "电信CTGNET [精品线路]",
"AS4809a": "电信CN2GIA [精品线路]",
"AS4809b": "电信CN2GT [优质线路]",
"AS4809": "电信CN2 [优质线路]",
"AS4134": "电信163 [普通线路]",
"AS9929": "联通9929 [优质线路]",
"AS4837": "联通4837 [普通线路]",

View File

@ -4,37 +4,55 @@ import (
"strings"
)
// 识别IPv6地址的ASN
func ipv6Asn(ip string) string {
switch {
// 电信CN2GIA
case strings.HasPrefix(ip, "2408:80"):
return "AS4809a"
// 电信CN2GT
case strings.HasPrefix(ip, "2408:8000"):
return "AS4809b"
// 电信163
case strings.HasPrefix(ip, "240e:") || strings.HasPrefix(ip, "2408:8"):
return "AS4134"
// 联通9929
case strings.HasPrefix(ip, "2408:8026:"):
return "AS9929"
// 联通4837
case strings.HasPrefix(ip, "2408:8000:"):
return "AS4837"
// 移动CMIN2
case strings.HasPrefix(ip, "2409:8880:"):
return "AS58807"
// 移动CMI
case strings.HasPrefix(ip, "2409:8000:") || strings.HasPrefix(ip, "2409:"):
return "AS9808"
// 移动CMI
case strings.HasPrefix(ip, "2407:") || strings.HasPrefix(ip, "2401:"):
return "AS58453"
// 电信CTGNET
case strings.HasPrefix(ip, "2402:0:") || strings.HasPrefix(ip, "2400:8:"):
return "AS23764"
default:
return ""
}
//go:embed bk/prefix/as4809.txt
var as4809Data string
//go:embed bk/prefix/as4134.txt
var as4134Data string
//go:embed bk/prefix/as9929.txt
var as9929Data string
//go:embed bk/prefix/as4837.txt
var as4837Data string
//go:embed bk/prefix/as58807.txt
var as58807Data string
//go:embed bk/prefix/as9808.txt
var as9808Data string
//go:embed bk/prefix/as58453.txt
var as58453Data string
//go:embed bk/prefix/as23764.txt
var as23764Data string
// ASN -> Prefix strings
var asnPrefixes = map[string][]string{
"AS4809": strings.Split(as4809Data, "\n"), // 电信 CN2 GT/GIA
"AS4134": strings.Split(as4134Data, "\n"), // 电信 163 骨干网
"AS9929": strings.Split(as9929Data, "\n"), // 联通 9929 优质国际线路
"AS4837": strings.Split(as4837Data, "\n"), // 联通 AS4837 普通国际线路
"AS58807": strings.Split(as58807Data, "\n"), // 移动 CMIN2 国际精品网
"AS9808": strings.Split(as9808Data, "\n"), // 移动 CMI中国移动国际公司
"AS58453": strings.Split(as58453Data, "\n"), // 移动国际互联网CMI/HK
"AS23764": strings.Split(as23764Data, "\n"), // 电信 CTGNET/国际出口可能是CN2-B
}
// 判断 IPv6 地址是否匹配 ASN 中的某个前缀
func ipv6Asn(ip string) string {
ip = strings.ToLower(ip)
for asn, prefixes := range asnPrefixes {
for _, prefix := range prefixes {
prefix = strings.TrimSpace(prefix)
if prefix == "" {
continue
}
if strings.HasPrefix(ip, prefix) {
return asn
}
}
}
return ""
}

24
bk/prefix/as23764.txt Normal file
View File

@ -0,0 +1,24 @@
2400:9380:9115
2400:9380:9116
2400:9380:9206
2400:9380:9262
2400:9380:a003
2400:9380:a00a
2400:9380:a00c
2400:9380:a01f
2400:9380:a022
2400:9380:a026
2400:9380:a028
2400:9380:a042
2400:9380:a110
2804:1e48:9003
2a04:f580:9001
2a04:f581:110a
2a04:f581:110b
2a04:f581:a123
2a04:f581:a125
2a0f:7806:fffc
2c0f:f7a8:1
2c0f:f7a8:29
2c0f:f7a8:37
2c0f:f7a8:47

223
bk/prefix/as4134.txt Normal file
View File

@ -0,0 +1,223 @@
2400:9380:8001
2400:9380:8003
2400:9380:8021
2400:9380:8030
2400:9380:8040
2400:9380:8140
2400:9380:8201
2400:9380:8221
2400:9380:8301
240e
240e:1
240e:100
240e:101
240e:103
240e:104
240e:106
240e:108
240e:11:8001
240e:12
240e:144
240e:16:1001
240e:16:1008
240e:16:1009
240e:184
240e:1c7
240e:2
240e:218
240e:219
240e:21a
240e:21b
240e:224
240e:225
240e:226
240e:227
240e:24
240e:240
240e:241
240e:242
240e:243
240e:244
240e:245
240e:246
240e:247
240e:2c
240e:318
240e:319
240e:31a
240e:31b
240e:324
240e:325
240e:326
240e:327
240e:340
240e:341
240e:342
240e:343
240e:350:205
240e:41
240e:418
240e:419
240e:41a
240e:41b
240e:42
240e:424
240e:425
240e:426
240e:427
240e:42:4000
240e:42:8010
240e:43
240e:43:8000
240e:44
240e:440
240e:441
240e:442
240e:443
240e:444
240e:445
240e:446
240e:447
240e:45
240e:45:8000
240e:46
240e:46:5008
240e:47
240e:47:4
240e:48
240e:49
240e:4a
240e:4b
240e:4b:2
240e:4c
240e:4c:4006
240e:4d
240e:4d:50ff
240e:4e
240e:4e:4000
240e:4f
240e:50
240e:51
240e:518
240e:519
240e:51a
240e:51b
240e:52
240e:524
240e:525
240e:526
240e:527
240e:53
240e:54
240e:540
240e:541
240e:542
240e:543
240e:544
240e:545
240e:546
240e:547
240e:55
240e:56
240e:57
240e:5a
240e:5b
240e:5c
240e:5d
240e:5e
240e:5f
240e:618
240e:619
240e:61a
240e:61b
240e:61d:1401
240e:624
240e:625
240e:626
240e:627
240e:638
240e:64
240e:640
240e:641
240e:642
240e:643
240e:659:1160
240e:7
240e:718
240e:719
240e:71a
240e:71b
240e:724
240e:725
240e:726
240e:727
240e:740
240e:741
240e:742
240e:743
240e:767
240e:840
240e:841
240e:9
240e:918
240e:919
240e:91a
240e:91b
240e:924
240e:925
240e:926
240e:927
240e:940
240e:941
240e:942
240e:943
240e:944
240e:945
240e:946
240e:947
240e:980
240e:981
240e:982
240e:983
240e:a0c
240e:a0d
240e:a0e
240e:a0f
240e:a18
240e:a19
240e:a1a
240e:a1b
240e:a24
240e:a25
240e:a26
240e:a27
240e:a40
240e:a41
240e:a42
240e:a43
240e:a44
240e:a45
240e:a46
240e:a47
240e:a5:8000
240e:b
240e:cd:8000
240e:d:100
2605:9d80:8001
2605:9d80:8011
2605:9d80:8021
2605:9d80:8031
2605:9d80:8041
2605:9d80:8081
2a04:f580:8010
2a04:f580:8011
2a04:f580:8090
2a04:f580:8210
2a04:f580:8211
2a04:f580:8290
2c0f:f7a8:8011
2c0f:f7a8:8050
2c0f:f7a8:805f
2c0f:f7a8:8150
2c0f:f7a8:815f
2c0f:f7a8:8211

160
bk/prefix/as4809.txt Normal file
View File

@ -0,0 +1,160 @@
2400:9380:9000
2400:9380:9001
2400:9380:9002
2400:9380:9005
2400:9380:9009
2400:9380:900a
2400:9380:9020
2400:9380:9021
2400:9380:9030
2400:9380:9031
2400:9380:9040
2400:9380:9041
2400:9380:9050
2400:9380:9051
2400:9380:9060
2400:9380:9061
2400:9380:9070
2400:9380:9071
2400:9380:9080
2400:9380:9081
2400:9380:90a0
2400:9380:90a1
2400:9380:90b0
2400:9380:90b1
2400:9380:90b2
2400:9380:90b3
2400:9380:90b4
2400:9380:90b5
2400:9380:90b6
2400:9380:90b7
2400:9380:9100
2400:9380:9101
2400:9380:9121
2400:9380:9201
2400:9380:9202
2400:9380:9205
2400:9380:9220
2400:9380:9221
2400:9380:9230
2400:9380:9231
2400:9380:9240
2400:9380:9241
2400:9380:9250
2400:9380:9251
2400:9380:9252
2400:9380:9260
2400:9380:9261
2400:9380:9270
2400:9380:9271
2400:9380:9272
2400:9380:9280
2400:9380:9281
2400:9380:9282
2400:9380:92a0
2400:9380:92a1
2400:9380:92b0
2400:9380:92b1
2400:9380:92b2
2400:9380:92b3
2400:9380:92b4
2400:9380:92b5
2400:9380:92b6
2400:9380:92b7
240e:182:5401
240e:182:5501
240e:409:9000
240e:409:9001
240e:410:ff00
240e:411:ff00
240e:414
240e:43d:fff1
240e:43d:fff3
240e:43d:fff4
240e:43d:fff7
240e:440:ac00
240e:440:ac01
240e:440:ac02
240e:441:ac00
240e:441:ac01
240e:441:ac02
240e:445:3f00
240e:446:3f00
240e:451:bfc0
240e:451:bfe0
240e:451:ffa0
240e:451:ffc0
240e:451:ffe0
240e:456:fe00
240e:457:fe00
240e:469:f400
240e:476:febf
240e:476:feff
240e:604:314
240e:60e:8000
240e:60e:8001
240e:615
240e:62c
240e:638:f
240e:63c
240e:640:178
240e:640:179
240e:640:17a
240e:640:17b
240e:648:1e
240e:64e
240e:659:f100
240e:669
240e:699:7a00
240e:699:7a01
240e:713:f020
240e:713:f021
240e:733:4c0
240e:f6:8002
2605:9d80:9003
2605:9d80:9013
2605:9d80:9023
2605:9d80:9033
2605:9d80:9042
2605:9d80:9052
2605:9d80:9061
2605:9d80:9071
2605:9d80:9092
2804:1e48
2804:1e48:9001
2804:1e48:9002
2a04:f580:9000
2a04:f580:9001
2a04:f580:9002
2a04:f580:9010
2a04:f580:9012
2a04:f580:9013
2a04:f580:9020
2a04:f580:9030
2a04:f580:9040
2a04:f580:9050
2a04:f580:9060
2a04:f580:9070
2a04:f580:9080
2a04:f580:9090
2a04:f580:9200
2a04:f580:9201
2a04:f580:9202
2a04:f580:9210
2a04:f580:9212
2a04:f580:9213
2a04:f580:9220
2a04:f580:9230
2a04:f580:9240
2a04:f580:9250
2a04:f580:9260
2a04:f580:9270
2a04:f580:9280
2a04:f580:9290
2c0f:f7a8:9010
2c0f:f7a8:9011
2c0f:f7a8:9020
2c0f:f7a8:9041
2c0f:f7a8:9210
2c0f:f7a8:9211
2c0f:f7a8:9220

414
bk/prefix/as4837.txt Normal file
View File

@ -0,0 +1,414 @@
2400:73e0:201
2402:f140:ff13
2402:f140:ff14
2404:6500:dcb3
2405:1480
2406:1e40
2406:cac0
2407:37c0:ffff
2407:6c40
2407:6c40:1500
2408
2408:8000
2408:8000:10fe
2408:8000:10ff
2408:8000:2
2408:8000:3
2408:8001
2408:802a
2408:802c
2408:8034
2408:803e
2408:8056
2408:80c2
2408:80c5
2408:80e2
2408:80e3
2408:80e9
2408:80f5
2408:80f9
2408:815f
2408:8181
2408:8182
2408:8183
2408:81a2
2408:81a3
2408:8210
2408:8211
2408:8212
2408:8213
2408:8214
2408:8215
2408:821a
2408:821b
2408:8220
2408:8221
2408:8226
2408:822a
2408:822b
2408:822e
2408:822f
2408:8230
2408:8231
2408:8232
2408:8233
2408:8234
2408:8235
2408:8236
2408:8237
2408:8238
2408:8239
2408:823c
2408:823d
2408:8240
2408:8248
2408:8249
2408:824a
2408:824b
2408:824c
2408:824e
2408:824f
2408:8250
2408:8251
2408:8252
2408:8253
2408:8254
2408:8255
2408:825c
2408:825d
2408:8260
2408:8262
2408:8263
2408:8264
2408:8265
2408:8266
2408:826a
2408:826c
2408:826d
2408:826e
2408:826f
2408:8270
2408:8274
2408:8275
2408:8276
2408:8277
2408:8278
2408:8279
2408:827a
2408:8310
2408:8311
2408:8312
2408:8313
2408:832a
2408:832e
2408:832f
2408:8330
2408:8331
2408:8332
2408:8333
2408:8338
2408:8340
2408:8348
2408:8349
2408:834a
2408:834b
2408:834e
2408:834f
2408:8350
2408:8351
2408:8352
2408:8353
2408:8354
2408:8355
2408:8360
2408:8361
2408:8362
2408:8363
2408:8364
2408:8365
2408:836c
2408:836d
2408:836e
2408:836f
2408:8374
2408:8375
2408:8376
2408:8377
2408:8378
2408:8379
2408:837a
2408:8410
2408:8411
2408:8412
2408:8413
2408:8414
2408:8415
2408:8417
2408:8418
2408:841a
2408:841b
2408:841c
2408:841d
2408:841e
2408:8420
2408:8421
2408:8422
2408:8426
2408:8427
2408:842a
2408:842b
2408:842c
2408:842e
2408:8431
2408:8434
2408:8435
2408:8436
2408:8437
2408:8438
2408:8439
2408:843c
2408:843d
2408:843e
2408:843f
2408:8440
2408:8441
2408:8448
2408:844b
2408:844c
2408:844d
2408:844e
2408:844f
2408:8452
2408:8453
2408:8454
2408:845c
2408:845d
2408:8460
2408:8461
2408:8462
2408:8463
2408:8464
2408:8465
2408:8466
2408:8469
2408:846a
2408:846b
2408:846c
2408:846d
2408:846e
2408:846f
2408:8470
2408:8471
2408:8474
2408:8475
2408:8476
2408:8477
2408:8478
2408:8479
2408:847a
2408:84e3
2408:84e4
2408:84e5
2408:84e6
2408:84e7
2408:84e9
2408:84eb
2408:84ec
2408:84ed
2408:84ee
2408:84ef
2408:84f0
2408:84f1
2408:84f2
2408:84f4
2408:84f5
2408:84f6
2408:84f7
2408:84f8
2408:84f9
2408:84fa
2408:84fb
2408:84fc
2408:84fd
2408:84fe
2408:84ff
2408:856c
2408:856d
2408:8610
2408:8611
2408:8612
2408:8613
2408:8614
2408:8615
2408:861a
2408:861b
2408:861c
2408:8620
2408:8621
2408:8624
2408:8625
2408:8626
2408:862a
2408:862b
2408:862d
2408:862e
2408:862f
2408:8630
2408:8631
2408:8632
2408:8633
2408:8634
2408:8635
2408:8636
2408:8637
2408:8638
2408:8639
2408:863c
2408:863d
2408:8640
2408:8642
2408:8648
2408:8649
2408:864c
2408:864e
2408:864f
2408:8650
2408:8651
2408:8652
2408:8653
2408:8654
2408:865c
2408:865d
2408:8660
2408:8662
2408:8663
2408:8664
2408:8665
2408:8666
2408:866a
2408:866b
2408:866c
2408:866d
2408:866e
2408:866f
2408:8670
2408:8674
2408:8675
2408:8676
2408:8677
2408:8678
2408:8679
2408:867a
2408:8710
2408:8711
2408:8712
2408:8713
2408:8719
2408:871a
2408:871b
2408:8720
2408:8721
2408:8722
2408:8723
2408:8726
2408:872b
2408:872f
2408:8730
2408:8731
2408:8732
2408:8733
2408:8734
2408:8735
2408:8736
2408:8738
2408:873c
2408:873d
2408:8740
2408:8742
2408:8748
2408:8749
2408:874a
2408:874b
2408:874c
2408:874d
2408:874e
2408:874f
2408:8752
2408:875c
2408:8760
2408:8762
2408:8763
2408:8764
2408:8765
2408:8766
2408:8768
2408:876a
2408:876c
2408:876d
2408:876e
2408:876f
2408:8770
2408:8772
2408:8773
2408:8774
2408:8776
2408:8777
2408:8778
2408:8779
2408:877a
2408:8812
2408:8813
2408:8814
2408:8815
2408:8816
2408:8817
2408:8818
2408:8819
2408:882c
2408:883a
2408:8862
2408:8863
2408:8864
2408:8865
2408:8866
2408:886e
2408:886f
2408:8872
2408:8878
2408:8879
2408:887e
2408:8912
2408:8913
2408:8914
2408:8915
2408:8916
2408:8917
2408:891c
2408:8920
2408:8924
2408:892c
2408:8936
2408:893a
2408:8940
2408:8948
2408:894c
2408:894e
2408:8962
2408:8963
2408:8964
2408:8965
2408:8966
2408:896c
2408:896e
2408:896f
2408:8972
2408:8978
2408:8979
2408:897a
2408:897b
2408:897e
2408:8a21
2408:8a23
2408:8a24
2408:8a26
2408:8a27

7
bk/prefix/as58453.txt Normal file
View File

@ -0,0 +1,7 @@
2400:8800:1f0e:5f
2400:8800:1f11:13
2401:cf80:620f:1
2402:4f00
2402:4f00:3000
2402:4f00:4000:4
2402:4f00:4003

2
bk/prefix/as58807.txt Normal file
View File

@ -0,0 +1,2 @@
2402:4f00
2402:4f00:f000

1332
bk/prefix/as9808.txt Normal file

File diff suppressed because it is too large Load Diff

26
bk/prefix/as9929.txt Normal file
View File

@ -0,0 +1,26 @@
2408:8120
2408:8120:1
2408:8120:2
2408:8256:226d
2408:8256:228b
2408:8610:3bff
2408:8614:1f0
2408:861c:1fff
2408:8625:10fb
2408:8626:f200
2408:862b
2408:862e:2ff
2408:8638:116
2408:8649:2a00
2408:8656:a52
2408:8660:100
2408:8678:1400
2408:8756:3efd
2408:8a00
2408:8a01
2408:8a02
2408:8a04
2408:8a06
2408:8a06:1
2408:8a06:100
2408:8a06:101