@@ -3516,7 +3516,7 @@ async function config_Json(userID, hostName, sub, UA, 请求CF反代IP, _url, fa
35163516 if ( enableSocks ) CF访问方法 = enableHttp ? "http" : "socks5" ;
35173517 else if ( proxyIP && proxyIP != '' ) CF访问方法 = "proxyip" ;
35183518 else if ( 请求CF反代IP == 'true' ) CF访问方法 = "auto" ;
3519-
3519+
35203520 let 域名地址 = hostName ;
35213521 let 端口 = 443 ;
35223522 let 传输层安全 = [ 'tls' , true ] ;
@@ -5769,15 +5769,7 @@ async function handleWebSocket(request) {
57695769 if ( enableSocks ) {
57705770 sock = enableHttp ? await httpConnect ( addr , port ) : await socks5Connect ( addr , port ) ;
57715771 } else {
5772- let 反代IP地址 = proxyIP , 反代IP端口 = 443 ;
5773- if ( proxyIP . includes ( ']:' ) ) {
5774- 反代IP端口 = parseInt ( proxyIP . split ( ']:' ) [ 1 ] ) || 反代IP端口 ;
5775- 反代IP地址 = proxyIP . split ( ']:' ) [ 0 ] + "]" || 反代IP地址 ;
5776- } else if ( proxyIP . split ( ':' ) . length === 2 ) {
5777- 反代IP端口 = parseInt ( proxyIP . split ( ':' ) [ 1 ] ) || 反代IP端口 ;
5778- 反代IP地址 = proxyIP . split ( ':' ) [ 0 ] || 反代IP地址 ;
5779- }
5780- if ( proxyIP . toLowerCase ( ) . includes ( '.tp' ) ) 反代IP端口 = parseInt ( proxyIP . toLowerCase ( ) . split ( '.tp' ) [ 1 ] . split ( '.' ) [ 0 ] ) || 反代IP端口 ;
5772+ const [ 反代IP地址 , 反代IP端口 ] = await 解析地址端口 ( proxyIP ) ;
57815773 try {
57825774 sock = connect ( { hostname : 反代IP地址 , port : 反代IP端口 } ) ;
57835775 } catch {
@@ -5814,4 +5806,44 @@ async function handleWebSocket(request) {
58145806 status : 101 ,
58155807 webSocket : client
58165808 } ) ;
5809+ }
5810+
5811+ async function 解析地址端口 ( proxyIP ) {
5812+ proxyIP = proxyIP . toLowerCase ( ) ;
5813+ if ( proxyIP . includes ( '.william' ) ) {
5814+ const williamResult = await ( async function 解析William域名 ( william ) {
5815+ try {
5816+ const response = await fetch ( `https://1.1.1.1/dns-query?name=${ william } &type=TXT` , { headers : { 'Accept' : 'application/dns-json' } } ) ;
5817+ if ( ! response . ok ) return null ;
5818+ const data = await response . json ( ) ;
5819+ const txtRecords = ( data . Answer || [ ] ) . filter ( record => record . type === 16 ) . map ( record => record . data ) ;
5820+ if ( txtRecords . length === 0 ) return null ;
5821+ let txtData = txtRecords [ 0 ] ;
5822+ if ( txtData . startsWith ( '"' ) && txtData . endsWith ( '"' ) ) txtData = txtData . slice ( 1 , - 1 ) ;
5823+ const prefixes = txtData . replace ( / \\ 0 1 0 / g, ',' ) . replace ( / \n / g, ',' ) . split ( ',' ) . map ( s => s . trim ( ) ) . filter ( Boolean ) ;
5824+ if ( prefixes . length === 0 ) return null ;
5825+ return prefixes [ Math . floor ( Math . random ( ) * prefixes . length ) ] ;
5826+ } catch ( error ) {
5827+ console . error ( '解析ProxyIP失败:' , error ) ;
5828+ return null ;
5829+ }
5830+ } ) ( proxyIP ) ;
5831+ proxyIP = williamResult || proxyIP ;
5832+ }
5833+ let 地址 = proxyIP , 端口 = 443 ;
5834+ if ( proxyIP . includes ( '.tp' ) ) {
5835+ const tpMatch = proxyIP . match ( / \. t p ( \d + ) / ) ;
5836+ if ( tpMatch ) 端口 = parseInt ( tpMatch [ 1 ] , 10 ) ;
5837+ return [ 地址 , 端口 ] ;
5838+ }
5839+ if ( proxyIP . includes ( ']:' ) ) {
5840+ const parts = proxyIP . split ( ']:' ) ;
5841+ 地址 = parts [ 0 ] + ']' ;
5842+ 端口 = parseInt ( parts [ 1 ] , 10 ) || 端口 ;
5843+ } else if ( proxyIP . includes ( ':' ) && ! proxyIP . startsWith ( '[' ) ) {
5844+ const colonIndex = proxyIP . lastIndexOf ( ':' ) ;
5845+ 地址 = proxyIP . slice ( 0 , colonIndex ) ;
5846+ 端口 = parseInt ( proxyIP . slice ( colonIndex + 1 ) , 10 ) || 端口 ;
5847+ }
5848+ return [ 地址 , 端口 ] ;
58175849}
0 commit comments