proxy-script
Version:
[此仓库](https://github.com/ProxyStorage/For-Own-Use)用于存储我个人日常使用的代理工具(Surge、QuantumultX、Loon)配置以及相关涉及到的脚本和规则。
413 lines (405 loc) • 12.7 kB
JavaScript
const { wifi, v4, v6 } = $network
const params = getParams($argument)
let cellularInfo = ''
let rootName = ''
let group = params.group
let allGroup = []
const radioGeneration = {
GPRS: '2.5G',
CDMA1x: '2.5G',
EDGE: '2.75G',
WCDMA: '3G',
HSDPA: '3.5G',
CDMAEVDORev0: '3.5G',
CDMAEVDORevA: '3.5G',
CDMAEVDORevB: '3.75G',
HSUPA: '3.75G',
eHRPD: '3.9G',
LTE: '4G',
NRNSA: '5G',
NR: '5G'
}
const carrierNames = loadCarrierNames()
if (!v4.primaryAddress && !v6.primaryAddress) {
$done({
title: '无网络',
content: '尚未连接网络\n请检查网络状态后重试',
icon: 'wifi.exclamationmark',
'icon-color': '#CB1B45'
})
} else {
if ($network['cellular-data']) {
const carrierId = $network['cellular-data'].carrier
const radio = $network['cellular-data'].radio
if (carrierId && radio) {
cellularInfo = carrierNames[carrierId]
? carrierNames[carrierId] +
' | ' +
radioGeneration[radio] +
' - ' +
radio
: '移动数据 | ' + radioGeneration[radio] + ' - ' + radio
}
}
$httpClient.get(
'http://ip-api.com/json',
async function (error, response, data) {
if (error) {
$done({
title: '发生错误',
content: '无法获取网络详情\n请检查网络状态后重试',
icon: 'wifi.exclamationmark',
'icon-color': '#CB1B45'
})
}
const info = JSON.parse(data)
rootName = (
await httpAPI(
'/v1/policy_groups/select?group_name=' +
encodeURIComponent(group) +
''
)
).policy
let proxy = await httpAPI('/v1/policy_groups')
for (var key in proxy) {
allGroup.push(key)
}
while (allGroup.includes(rootName) == true) {
rootName = (
await httpAPI(
'/v1/policy_groups/select?group_name=' +
encodeURIComponent(rootName) +
''
)
).policy
}
$done({
title: wifi.ssid
? `当前使用WiFi:${wifi.ssid}`
: `当前使用数据:${cellularInfo}`,
content:
`当前节点:${rootName}\n` +
`节点 IP : ${info.query}\n` +
`节点 ISP : ${info.isp}\n` +
`节点位置 : ${getFlagEmoji(info.countryCode)} | ${info.country} - ${
info.city
}\n` +
(v4.primaryAddress ? `IPv4 : ${v4.primaryAddress} \n` : '') +
(v6.primaryAddress ? `IPv6 : ${v6.primaryAddress}\n` : '') +
(v4.primaryRouter && wifi.ssid
? `Router IPv4 : ${v4.primaryRouter}\n`
: '') +
(v6.primaryRouter && wifi.ssid
? `Router IPv6 : ${v6.primaryRouter}\n`
: '') +
'',
icon: wifi.ssid ? 'wifi' : 'simcard',
'icon-color': wifi.ssid ? '#005CAF' : '#F9BF45'
})
}
)
}
function getFlagEmoji(countryCode) {
const codePoints = countryCode
.toUpperCase()
.split('')
.map((char) => 127397 + char.charCodeAt())
return String.fromCodePoint(...codePoints)
}
function loadCarrierNames() {
//整理邏輯:前三碼相同->後兩碼同電信->剩下的
return {
//台灣電信業者 Taiwan
'466-11': '中華電信',
'466-92': '中華電信',
'466-01': '遠傳電信',
'466-03': '遠傳電信',
'466-97': '台灣大哥大',
'466-89': '台灣之星',
'466-05': 'GT',
//中國電信業者 China
'460-03': '中国电信',
'460-05': '中国电信',
'460-11': '中国电信',
'460-01': '中国联通',
'460-06': '中国联通',
'460-09': '中国联通',
'460-00': '中国移动',
'460-02': '中国移动',
'460-04': '中国移动',
'460-07': '中国移动',
'460-08': '中国移动',
'460-15': '中国广电',
'460-20': '中移铁通',
//香港電信業者 HongKong
'454-00': 'CSL',
'454-02': 'CSL',
'454-10': 'CSL',
'454-18': 'CSL',
'454-03': '3',
'454-04': '3',
'454-05': '3',
'454-06': 'SMC HK',
'454-15': 'SMC HK',
'454-17': 'SMC HK',
'454-09': 'CMHK',
'454-12': 'CMHK',
'454-13': 'CMHK',
'454-28': 'CMHK',
'454-31': 'CMHK',
'454-16': 'csl.',
'454-19': 'csl.',
'454-20': 'csl.',
'454-29': 'csl.',
'454-01': '中信國際電訊',
'454-07': 'UNICOM HK',
'454-08': 'Truphone',
'454-11': 'CHKTL',
'454-23': 'Lycamobile',
//日本電信業者 Japan
'440-00': 'Y!mobile',
'440-10': 'docomo',
'440-11': 'Rakuten',
'440-20': 'SoftBank',
'440-50': ' au',
'440-51': ' au',
'440-52': ' au',
'440-53': ' au',
'440-54': ' au',
'441-00': 'WCP',
'441-10': 'UQ WiMAX',
//韓國電信業者 Korea
'450-03': 'SKT',
'450-05': 'SKT',
'450-02': 'KT',
'450-04': 'KT',
'450-08': 'KT',
'450-06': 'LG U+',
'450-10': 'LG U+',
//美國電信業者 USA
'310-030': 'AT&T',
'310-070': 'AT&T',
'310-150': 'AT&T',
'310-170': 'AT&T',
'310-280': 'AT&T',
'310-380': 'AT&T',
'310-410': 'AT&T',
'310-560': 'AT&T',
'310-680': 'AT&T',
'310-980': 'AT&T',
'310-160': 'T-Mobile',
'310-200': 'T-Mobile',
'310-210': 'T-Mobile',
'310-220': 'T-Mobile',
'310-230': 'T-Mobile',
'310-240': 'T-Mobile',
'310-250': 'T-Mobile',
'310-260': 'T-Mobile',
'310-270': 'T-Mobile',
'310-300': 'T-Mobile',
'310-310': 'T-Mobile',
'310-660': 'T-Mobile',
'310-800': 'T-Mobile',
'311-660': 'T-Mobile',
'311-882': 'T-Mobile',
'311-490': 'T-Mobile',
'312-530': 'T-Mobile',
'311-870': 'T-Mobile',
'311-880': 'T-Mobile',
'310-004': 'Verizon',
'310-010': 'Verizon',
'310-012': 'Verizon',
'310-013': 'Verizon',
'311-110': 'Verizon',
'311-270': 'Verizon',
'311-271': 'Verizon',
'311-272': 'Verizon',
'311-273': 'Verizon',
'311-274': 'Verizon',
'311-275': 'Verizon',
'311-276': 'Verizon',
'311-277': 'Verizon',
'311-278': 'Verizon',
'311-279': 'Verizon',
'311-280': 'Verizon',
'311-281': 'Verizon',
'311-282': 'Verizon',
'311-283': 'Verizon',
'311-284': 'Verizon',
'311-285': 'Verizon',
'311-286': 'Verizon',
'311-287': 'Verizon',
'311-288': 'Verizon',
'311-289': 'Verizon',
'311-390': 'Verizon',
'311-480': 'Verizon',
'311-481': 'Verizon',
'311-482': 'Verizon',
'311-483': 'Verizon',
'311-484': 'Verizon',
'311-485': 'Verizon',
'311-486': 'Verizon',
'311-487': 'Verizon',
'311-488': 'Verizon',
'311-489': 'Verizon',
'310-590': 'Verizon',
'310-890': 'Verizon',
'310-910': 'Verizon',
'310-120': 'Sprint',
'310-850': 'Aeris Comm. Inc.',
'310-510': 'Airtel Wireless LLC',
'312-090': 'Allied Wireless Communications Corporation',
'310-710': 'Arctic Slope Telephone Association Cooperative Inc.',
'311-440': 'Bluegrass Wireless LLC',
'311-800': 'Bluegrass Wireless LLC',
'311-810': 'Bluegrass Wireless LLC',
'310-900': 'Cable & Communications Corp.',
'311-590': 'California RSA No. 3 Limited Partnership',
'311-500': 'Cambridge Telephone Company Inc.',
'310-830': 'Caprock Cellular Ltd.',
'312-270': 'Cellular Network Partnership LLC',
'312-280': 'Cellular Network Partnership LLC',
'310-360': 'Cellular Network Partnership LLC',
'311-120': 'Choice Phone LLC',
'310-480': 'Choice Phone LLC',
'310-420': 'Cincinnati Bell Wireless LLC',
'310-180': 'Cingular Wireless',
'310-620': 'Coleman County Telco /Trans TX',
'310-06': 'Consolidated Telcom',
'310-60': 'Consolidated Telcom',
'310-700': 'Cross Valliant Cellular Partnership',
'312-030': 'Cross Wireless Telephone Co.',
'311-140': 'Cross Wireless Telephone Co.',
'312-040': 'Custer Telephone Cooperative Inc.',
'310-440': 'Dobson Cellular Systems',
'310-990': 'E.N.M.R. Telephone Coop.',
'312-120': 'East Kentucky Network LLC',
'312-130': 'East Kentucky Network LLC',
'310-750': 'East Kentucky Network LLC',
'310-090': 'Edge Wireless LLC',
'310-610': 'Elkhart TelCo. / Epic Touch Co.',
'311-311': 'Farmers',
'311-460': 'Fisher Wireless Services Inc.',
'311-370': 'GCI Communication Corp.',
'310-430': 'GCI Communication Corp.',
'310-920': 'Get Mobile Inc.',
'311-340': 'Illinois Valley Cellular RSA 2 Partnership',
'312-170': 'Iowa RSA No. 2 Limited Partnership',
'311-410': 'Iowa RSA No. 2 Limited Partnership',
'310-770': 'Iowa Wireless Services LLC',
'310-650': 'Jasper',
'310-870': 'Kaplan Telephone Company Inc.',
'312-180': 'Keystone Wireless LLC',
'310-690': 'Keystone Wireless LLC',
'311-310': 'Lamar County Cellular',
'310-016': 'Leap Wireless International Inc.',
'310-040': 'Matanuska Tel. Assn. Inc.',
'310-780': 'Message Express Co. / Airlink PCS',
'311-330': 'Michigan Wireless LLC',
'310-400': 'Minnesota South. Wirel. Co. / Hickory',
'311-010': 'Missouri RSA No 5 Partnership',
'312-010': 'Missouri RSA No 5 Partnership',
'311-020': 'Missouri RSA No 5 Partnership',
'312-220': 'Missouri RSA No 5 Partnership',
'311-920': 'Missouri RSA No 5 Partnership',
'310-350': 'Mohave Cellular LP',
'310-570': 'MTPCS LLC',
'310-290': 'NEP Cellcorp Inc.',
'310-34': 'Nevada Wireless LLC',
'310-600': 'New-Cell Inc.',
'311-300': 'Nexus Communications Inc.',
'310-130': 'North Carolina RSA 3 Cellular Tel. Co.',
'312-230': 'North Dakota Network Company',
'311-610': 'North Dakota Network Company',
'310-450': 'Northeast Colorado Cellular Inc.',
'311-710': 'Northeast Wireless Networks LLC',
'310-011': 'Northstar',
'310-670': 'Northstar',
'311-420': 'Northwest Missouri Cellular Limited Partnership',
'310-760': 'Panhandle Telephone Cooperative Inc.',
'310-580': 'PCS ONE',
'311-170': 'PetroCom',
'311-670': 'Pine Belt Cellular, Inc.',
'310-100': 'Plateau Telecommunications Inc.',
'310-940': 'Poka Lambro Telco Ltd.',
'310-500': 'Public Service Cellular Inc.',
'312-160': 'RSA 1 Limited Partnership',
'311-430': 'RSA 1 Limited Partnership',
'311-350': 'Sagebrush Cellular Inc.',
'310-46': 'SIMMETRY',
'311-260': 'SLO Cellular Inc / Cellular One of San Luis',
'310-320': 'Smith Bagley Inc.',
'316-011': 'Southern Communications Services Inc.',
'310-740': 'Telemetrix Inc.',
'310-14': 'Testing',
'310-860': 'Texas RSA 15B2 Limited Partnership',
'311-050': 'Thumb Cellular Limited Partnership',
'311-830': 'Thumb Cellular Limited Partnership',
'310-460': 'TMP Corporation',
'310-490': 'Triton PCS',
'312-290': 'Uintah Basin Electronics Telecommunications Inc.',
'311-860': 'Uintah Basin Electronics Telecommunications Inc.',
'310-960': 'Uintah Basin Electronics Telecommunications Inc.',
'310-020': 'Union Telephone Co.',
'311-220': 'United States Cellular Corp.',
'310-730': 'United States Cellular Corp.',
'311-650': 'United Wireless Communications Inc.',
'310-003': 'Unknown',
'310-15': 'Unknown',
'310-23': 'Unknown',
'310-24': 'Unknown',
'310-25': 'Unknown',
'310-26': 'Unknown',
'310-190': 'Unknown',
'310-950': 'Unknown',
'310-38': 'USA 3650 AT&T',
'310-999': 'Various Networks',
'310-520': 'VeriSign',
'310-530': 'West Virginia Wireless',
'310-340': 'Westlink Communications, LLC',
'311-070': 'Wisconsin RSA #7 Limited Partnership',
'310-390': 'Yorkville Telephone Cooperative',
//英國電信業者 UK
'234-08': 'BT OnePhone UK',
'234-10': 'O2-UK',
'234-15': 'vodafone UK',
'234-20': '3',
'234-30': 'EE',
'234-33': 'EE',
'234-38': 'Virgin',
'234-50': 'JT',
'234-55': 'Sure',
'234-58': 'Manx Telecom',
//菲律賓電信業者 Philippine
'515-01': 'Islacom',
'515-02': 'Globe',
'515-03': 'Smart',
'515-04': 'Sun',
'515-08': 'Next Mobile',
'515-18': 'Cure',
'515-24': 'ABS-CBN',
//越南電信業者 Vietnam
'452-01': 'Mobifone',
'452-02': 'VinaPhone',
'452-03': 'S-Fone',
'452-04': 'Viettel',
'452-05': 'VietNamobile',
'452-06': 'E-mobile',
'452-07': 'Gmobile'
}
}
function httpAPI(path = '', method = 'GET', body = null) {
return new Promise((resolve) => {
$httpAPI(method, path, body, (result) => {
resolve(result)
})
})
}
function getParams(param) {
return Object.fromEntries(
$argument
.split('&')
.map((item) => item.split('='))
.map(([k, v]) => [k, decodeURIComponent(v)])
)
}