socat安装

socat的主要特点就是在两个数据流之间建立通道;且支持众多协议和链接方式:ip, tcp, udp, ipv6, pipe,exec,system,open,proxy,openssl,socket等。
socat是一个多功能的网络工具,名字来由是” Socket CAT”,可以看作是netcat的N
倍加强版,socat的官方网站:http://www.dest-unreach.org/socat/

安装:http://www.dest-unreach.org/socat/download/

安装步骤:

1.解压
2.   ./configure 
3.   make && make install
    编译时出现:
    gcc -O -D_GNU_SOURCE -Wall -Wno-parentheses  -DHAVE_CONFIG_H -I.  -I.   -c -o nestlex.o nestlex.c
nestlex.c:14:7: error: unknown type name ‘ptrdiff_t’
       ptrdiff_t *len, 后面还有很多

解决办法:
vim nestlex.c 添加在头部 #include "stddef.h" 保存
在编译

如果出现:    

这里写图片描述

解决方法有两种:
第一种是禁用fips,使用如下命令配置:
./configure –disable-fips
第二种是安装fips,首先到网站http://www.openssl.org/source/ 下载openssl-fips安装包,然后解压安装:
./configure
make && make install

socat使用:

    工作原理:
    四个阶段:
        初始化:解析命令行以及初始化日志系统
        打开连接:先打开第一个连接,再打开第二个连接,是单步执行的,第一个失败,直接退出
        数据转发:谁有数据就转发到另外一个连接上,read/write互换
        关闭:其中一个连接掉开,执行处理另外一个连接关闭


3.2 地址类型 
参数由2部分组成,第一个连接和第二个连接,最简单的用法就是 socat - - 其效果就是输入什么,回显什么其用法主要在于地址如何描述, 下面介绍几个常用的。 
3.2.1 TCP 
TCP:<host>:<port> 目标机器host对应端口portTCP-LISTEN:<port> 本机监听端口。 
3.2.2 UDP 
UDP:<host>:<port> 目标机器host对应端口portUDP-LISTEN:<port> 本机监听端口。 
3.2.3 OPENSSL 
需要一个证书,否则会失败提示: 2012/04/06 11:29:11 socat[1614] E SSL_connect(): 
error:14077410:SSL routines:SSL23_GET_SERVER_HELLO:sslv3 alert handshake failureOPENSSL:<host>:<port> 目标机器host
对应端口
portOPENSSL-LISTEN:<port> 本机监听端口。 
3.2.4 TUN 
TUN[:<if-addr>/<bits>] 建立vpn,双方都需要root权限。 

3.3 典型使用 
3.3.1 连接目标 
socat - tcp:192.168.1.18:80 
这个命令等同于 nc 192.168.1.18 80。 socat里面,必须有两个流,所以第一个参数-代表标准的输入输出,第二个流连接到192.168.1.18的80端口。 
socat -d -d READLINE,history=$HOME/.http_history TCP4:www.qq.com:80 
这个例子支持历史记录查询,类似于bash的历史记录。 
3.3.2 反向连接 
再看一个反向telnet的例子: on server: 
socat tcp-listen:23 exec:cmd,pty,stderr 
这个命名把cmd绑定到端口23,同时把cmd的Stderr复位向到stdout。 on client: 
socat readline tcp:server:23 
连接到服务器的23端口,即可获得一个cmd shell。readline是gnu的命令行编辑器,具有历史功能。 
3.3.3 向远处端口发数据 
echo “test” | socat – tcp-connect:127.0.0.1:12345 
3.3.4 本地开启端口 
socat tcp-l:7777,reuseaddr,fork system:bash 
同nc -l -p 7777 -e bash。 
3.3.5 执行bash的完美用法 
在目标上 
socat tcp-l:8888 system:bash,pty,stderr 
本地 
socat readline tcp:$target:8888readline替代-,就能支持历史功能了。在这个模式下的客户端有本地一样的效果 

3.3.6 文件传递 
再看文件传递的例子。nc也经常用来传递文件,但是nc有一个缺点,就是不知道文件什么时候传完了,一般要用Ctrl+c来终止,或者估计一个时间,用-w参数来让他自动终止。用socat就不用这么麻烦了: 
on host 1: 
socat -u open:myfile.exe,binary tcp-listen:999 
on host 2: 
socat -u tcp:host1:999 open:myfile.exe,create,binary 
这个命令把文件myfile.exe用二进制的方式,从host 1 传到host 2。-u 表示数据单向流动,从第一个参数到第二个参数,-U表示从第二个到第一个。文件传完了,自动退出。 

3.3.7 转发 

3.3.7.1 本地端口转向远程主机 
socat TCP4-LISTEN:8888 TCP4:www.qq.com:80 
如果需要使用并发连接,则加一个fork,如下: 
socat TCP4-LISTEN:8888,fork TCP4:www.qq.com:80 
本地监听8888端口,来自8888的连接重定向到目标www.qq.com:80 
3.3.7.2 端口映射 
再来一个大家喜欢用的例子。在一个NAT环境,如何从外部连接到内部的一个端口呢?只要能够在内部运行socat就可以了。 
外部: 
socat tcp-listen:1234 tcp-listen:3389 
内部: 
socat tcp:outerhost:1234 tcp:192.168.12.34:3389 
这样,你外部机器上的3389就映射在内部网192.168.12.343389端口上。 

3.3.7.3 VPN 
服务端 
socat -d -d TCP-LISTEN:11443,reuseaddr TUN:192.168.255.1/24,up 
客户端 
socat TCP:1.2.3.4:11443 TUN:192.168.255.2/24,up 

3.3.8 重定向 
socat TCP4-LISTEN:80,reuseaddr,fork TCP4:192.168.123.12:8080 
TCP4-LISTEN:在本地建立的是一个TCP ipv4协议的监听端口; reuseaddr:绑定本地一个端口; 
fork:设定多链接模式,即当一个链接被建立后,自动复制一个同样的端口再进行监听 
socat启动监听模式会在前端占用一个shell,因此需使其在后台执行。 
socat -d -d tcp4-listen:8900,reuseaddr,fork tcp4:10.5.5.10:3389 # 端口转发 
或者 
socat -d -d -lf /var/log/socat.log TCP4-LISTEN:15000,reuseaddr,fork,su=nobody TCP4:static.5iops.com:15000 
“-d -d -lf /var/log/socat.log”是参数,前面两个连续的-d -d代表调试信息的输出级别,-lf则指定输出信息的保存文件。 
“TCP4-LISTEN:15000,reuseaddr,fork,su=nobody”是一号地址,代表在15000端口上进行TCP4协议的监听,复用绑定的IP,每次有连接到来就fork复制一个进程进行处理,同时将执行用户设置为nobody用户。 
“TCP4:static.5iops.com:15000″是二号地址,代表将socat监听到的任何请求,转发到static.5iops.com:15000上去。 

3.3.9 读写分流 
socat还具有一个独特的读写分流功能,比如: 
socat open:read.txt!!open:write.txt,create,append tcp-listen:80,reuseaddr,fork 
这个命令实现一个假的web server,客户端连过来之后,就把read.txt里面的内容发过去,同时把客户的数据保存到write.txt里面。”!!”符号用户合并读写流,前面的用于读,后面的用于写。 

3.3.10 通过openssl来加密传输过程 

3.3.10.1 
证书生成 
FILENAME=server openssl genrsa -out $FILENAME.key 1024openssl req -new -key $FILENAME.key -x509 -days 3653 -out 
$FILENAME.crtcat 
$FILENAME.key 
$FILENAME.crt >$FILENAME.pem 
在当前目录下生成 server.pem server.crt
3.3.10.2 使用 
在服务端 
socat openssl-listen:4433,reuseaddr,cert=srv.pem,cafile=srv.crt system:bash,pty,stderr 
在本地 
socat readline openssl:localhost:4433,cert=srv.pem,cafile=srv.crt 

apt-get install socat nohup

nohup socat TCP4-LISTEN:2333,reuseaddr,fork TCP4:233.233.233.233:6666 >> /root/socat.log 2>&1 &
nohup socat UDP4-LISTEN:2333,reuseaddr,fork UDP4:233.233.233.233:6666 >> /root/socat.log 2>&1 &

其中 TCP4/UDP4-LISTEN: 处填写转发服务器(即本机)的端口,TCP4/UDP4: 处填写被转发服务器的 IP 和对应被转发端口(即 SS 服务器)

设置完成后把 SS 的客户端的 服务器地址 和 端口 改为国内转发服务器对应的 IP 和端口即可

开机自启:
chmod +x /etc/rc.d/rc.local
vi /etc/rc.d/rc.local
WARNING: Enabling and disabling experimental features do not take effect until next start of PowerShell. WARNING: Enabling and disabling experimental features do not take effect until next start of PowerShell. [PS7 20:48:07] C:\Users\Administrator\Desktop [master] > function Install-Socat { >> param( >> [Parameter(Mandatory = $false)] >> [string]$InstallDrive = "E:", >> >> [Parameter(Mandatory = $false)] >> [string]$InstallDir = "Program Files\Socat" >> ) >> >> # 1. 规范化路径 >> $fullPath = [System.IO.Path]::GetFullPath("$InstallDrive\$InstallDir").TrimEnd('\') >> >> # 2. 管理员权限检查 >> if (-not ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) { >> Write-Warning "需要管理员权限安装程序" >> return $null >> } >> >> # 3. 检查现有安装 >> $existingPath = (Get-Command socat -ErrorAction SilentlyContinue | >> Select-Object -ExpandProperty Source -First 1) ?? $null >> >> if ($existingPath) { >> Write-Host "已安装于: $existingPath" -ForegroundColor Green >> return $existingPath >> } >> >> # 4. 创建安装目录 >> try { >> if (-not (Test-Path $fullPath)) { >> $null = New-Item -Path $fullPath -ItemType Directory -Force >> } >> } catch { >> Write-Error "创建目录失败: $($_.Exception.Message)" >> return $null >> } >> >> # 5. 更新下载源(修复404问题) >> $tempFile = Join-Path $env:TEMP "socat-win64.zip" >> $downloadUrls = @( >> "https://github.com/spacemeowx2/socat-windows/releases/download/v1.7.4.4/socat_x64.zip", # 添加v前缀 >> "https://github.com/spacemeowx2/socat-windows/releases/download/1.7.4.4/socat_x64.zip", >> "https://github.com/spacemeowx2/socat-windows/releases/latest/download/socat_x64.zip" # 添加最新版通用链接 >> ) >> >> $validDownload = $false >> $lastError = $null >> >> # 6. 重试下载逻辑 >> :downloadLoop foreach ($downloadUrl in $downloadUrls) { >> try { >> Write-Host "尝试从 $downloadUrl 下载..." -ForegroundColor Cyan >> try { >> $ProgressPreference = 'SilentlyContinue' >> Invoke-WebRequest $downloadUrl -OutFile $tempFile -UseBasicParsing -RetryIntervalSec 3 -ErrorAction Stop >> >> # 文件大小验证(至少500KB) >> $fileInfo = Get-Item $tempFile >> if ($fileInfo.Length -lt 500KB) { >> $lastError = "文件过小 ($([math]::Round($fileInfo.Length/1KB)) KB)" >> Write-Warning "文件校验失败: $lastError" >> Remove-Item $tempFile -Force >> continue >> } >> >> $validDownload = $true >> Write-Host "下载成功" -ForegroundColor Green >> break downloadLoop >> } catch { >> $lastError = $_.Exception.Message >> Write-Warning "下载失败 (Invoke-WebRequest): $lastError" >> } >> >> # 7. 备用下载方法 >> try { >> Write-Host "尝试备用下载方法 (WebClient)..." -ForegroundColor Yellow >> (New-Object System.Net.WebClient).DownloadFile($downloadUrl, $tempFile) >> >> $fileInfo = Get-Item $tempFile >> if ($fileInfo.Length -lt 500KB) { >> $lastError = "文件过小 ($([math]::Round($fileInfo.Length/1KB)) KB)" >> Write-Warning "文件校验失败: $lastError" >> Remove-Item $tempFile -Force >> continue >> } >> >> $validDownload = $true >> break downloadLoop >> } catch { >> $lastError = $_.Exception.Message >> Write-Warning "下载失败 (WebClient): $lastError" >> } >> } finally { >> $ProgressPreference = 'Continue' >> } >> } >> >> # 8. 处理下载失败 >> if (-not $validDownload) { >> Write-Error "所有下载源均失败。最后错误: $lastError" >> >> # 提供手动安装指南 >> Write-Host @" >> 手动安装步骤: >> 1. 从以下链接下载最新版socat: >> https://github.com/spacemeowx2/socat-windows/releases >> 2. 解压到目录: $fullPath >> 3. 添加PATH环境变量: >> [Environment]::SetEnvironmentVariable('Path', `$env:Path + `";$fullPath`", 'Machine') >> 4. 重启PowerShell会话 >> "@ -ForegroundColor Yellow >> >> # 自动打开浏览器 >> try { >> Start-Process "https://github.com/spacemeowx2/socat-windows/releases" >> } catch { >> Write-Warning "无法打开浏览器" >> } >> >> return $null >> } >> >> # 9. 解压文件 >> try { >> Expand-Archive -Path $tempFile -DestinationPath $fullPath -Force >> >> # 查找socat.exe >> $socatExe = Get-ChildItem -Path $fullPath -Filter "socat.exe" -Recurse | >> Select-Object -First 1 -ExpandProperty FullName >> >> if (-not $socatExe) { >> throw "解压后未找到 socat.exe" >> } >> >> # 移动到根目录 >> if ($socatExe -ne (Join-Path $fullPath "socat.exe")) { >> Move-Item -Path $socatExe -Destination $fullPath -Force >> $socatExe = Join-Path $fullPath "socat.exe" >> } >> } catch { >> Write-Error "解压失败: $($_.Exception.Message)" >> return $null >> } >> >> # 10. 更新环境变量 >> $currentPath = [Environment]::GetEnvironmentVariable("Path", "Machine") >> if ($currentPath -notlike "*$fullPath*") { >> [Environment]::SetEnvironmentVariable("Path", "$currentPath;$fullPath", "Machine") >> } >> >> # 11. 更新当前会话PATH >> $env:Path += ";$fullPath" >> >> # 12. 验证安装 >> if (Test-Path $socatExe) { >> Write-Host "socat 安装成功: $socatExe" -ForegroundColor Green >> return $socatExe >> } else { >> Write-Error "安装后文件验证失败" >> return $null >> } >> } [PS7 20:48:13] C:\Users\Administrator\Desktop [master] > function New-TcpTunnel { >> param( >> [int]$LocalPort = 8443, >> [string]$RemoteHost = "example.com", >> [int]$RemotePort = 80, >> [string]$SocatPath = $null, >> [int]$TimeoutSeconds = 15 >> ) >> >> # 1. 获取socat路径 >> $socatBinary = if ($SocatPath -and (Test-Path $SocatPath)) { >> $SocatPath >> } else { >> $installedPath = Install-Socat >> if (-not $installedPath) { >> throw "socat安装失败,请检查错误日志" >> } >> $installedPath >> } >> >> # 2. 验证socat可执行文件 >> if (-not (Test-Path $socatBinary -PathType Leaf)) { >> throw "socat可执行文件不存在: $socatBinary" >> } >> >> # 3. 创建日志文件 >> $logTime = Get-Date -Format "yyyyMMdd-HHmmss" >> $stdOutFile = Join-Path $env:TEMP "socat-$LocalPort-$logTime-out.log" >> $stdErrFile = Join-Path $env:TEMP "socat-$LocalPort-$logTime-err.log" >> >> # 4. 修复进程启动参数 >> try { >> $process = Start-Process -FilePath $socatBinary ` >> -ArgumentList "TCP-LISTEN:$LocalPort,fork,reuseaddr TCP:$($RemoteHost):$RemotePort" ` >> -NoNewWindow ` >> -RedirectStandardOutput $stdOutFile ` >> -RedirectStandardError $stdErrFile ` >> -PassThru >> } catch { >> Write-Error "启动socat失败: $($_.Exception.Message)" >> if (Test-Path $stdErrFile) { >> Write-Warning "错误日志: $(Get-Content $stdErrFile -Raw)" >> } >> throw >> } >> >> # 5. 端口监听验证(增强版) >> $portActive = $false >> $startTime = Get-Date >> $maxAttempts = $TimeoutSeconds >> $attempt = 0 >> >> while (-not $portActive -and $attempt -lt $maxAttempts) { >> Start-Sleep -Seconds 1 >> $attempt++ >> >> # 检查端口状态 >> try { >> $connection = Test-NetConnection -ComputerName localhost -Port $LocalPort -InformationLevel Quiet >> $portActive = $connection -eq $true >> } catch { >> $portActive = $false >> } >> >> # 检查进程状态 >> if ($process.HasExited) { >> $exitCode = $process.ExitCode >> $errorLog = if (Test-Path $stdErrFile) { Get-Content $stdErrFile -Raw } else { "无错误日志" } >> throw "socat进程已退出 (代码: $exitCode)。错误信息: $errorLog" >> } >> } >> >> if (-not $portActive) { >> $errorLog = if (Test-Path $stdErrFile) { Get-Content $stdErrFile -Raw } else { "无错误日志" } >> throw "隧道创建失败,端口 $LocalPort 未激活。错误信息: $errorLog" >> } >> >> # 6. 返回隧道信息 >> return [PSCustomObject]@{ >> Process = $process >> Port = $LocalPort >> StdOutLog = $stdOutFile >> StdErrLog = $stdErrFile >> Status = "Active" >> } >> } [PS7 20:48:17] C:\Users\Administrator\Desktop [master] > # 1. 安装socat(指定安装位置) [PS7 20:48:22] C:\Users\Administrator\Desktop [master] > $socatPath = Install-Socat -InstallDrive "D:" -InstallDir "NetTools" 尝试从 https://github.com/spacemeowx2/socat-windows/releases/download/v1.7.4.4/socat_x64.zip 下载... WARNING: 下载失败 (Invoke-WebRequest): Response status code does not indicate success: 404 (Not Found). 尝试备用下载方法 (WebClient)... WARNING: 下载失败 (WebClient): Exception calling "DownloadFile" with "2" argument(s): "The remote server returned an error: (404) Not Found." 尝试从 https://github.com/spacemeowx2/socat-windows/releases/download/1.7.4.4/socat_x64.zip 下载... WARNING: 下载失败 (Invoke-WebRequest): Response status code does not indicate success: 404 (Not Found). 尝试备用下载方法 (WebClient)... WARNING: 下载失败 (WebClient): Exception calling "DownloadFile" with "2" argument(s): "The remote server returned an error: (404) Not Found." 尝试从 https://github.com/spacemeowx2/socat-windows/releases/latest/download/socat_x64.zip 下载... WARNING: 下载失败 (Invoke-WebRequest): Response status code does not indicate success: 404 (Not Found). 尝试备用下载方法 (WebClient)... WARNING: 下载失败 (WebClient): Exception calling "DownloadFile" with "2" argument(s): "The remote server returned an error: (404) Not Found." Install-Socat: 所有下载源均失败。最后错误: Exception calling "DownloadFile" with "2" argument(s): "The remote server returned an error: (404) Not Found." 手动安装步骤: 1. 从以下链接下载最新版socat: https://github.com/spacemeowx2/socat-windows/releases 2. 解压到目录: D:\NetTools 3. 添加PATH环境变量: [Environment]::SetEnvironmentVariable('Path', $env:Path + ";D:\NetTools", 'Machine') 4. 重启PowerShell会话 [PS7 20:48:42] C:\Users\Administrator\Desktop [master] > [PS7 20:48:42] C:\Users\Administrator\Desktop [master] > # 2. 创建隧道(带参数验证) [PS7 20:48:43] C:\Users\Administrator\Desktop [master] > $tunnel = New-TcpTunnel -LocalPort 8080 -RemoteHost "example.com" -RemotePort 80 尝试从 https://github.com/spacemeowx2/socat-windows/releases/download/v1.7.4.4/socat_x64.zip 下载... WARNING: 下载失败 (Invoke-WebRequest): Response status code does not indicate success: 404 (Not Found). 尝试备用下载方法 (WebClient)... WARNING: 下载失败 (WebClient): Exception calling "DownloadFile" with "2" argument(s): "The remote server returned an error: (404) Not Found." 尝试从 https://github.com/spacemeowx2/socat-windows/releases/download/1.7.4.4/socat_x64.zip 下载... WARNING: 下载失败 (Invoke-WebRequest): Response status code does not indicate success: 404 (Not Found). 尝试备用下载方法 (WebClient)... WARNING: 下载失败 (WebClient): Exception calling "DownloadFile" with "2" argument(s): "The remote server returned an error: (404) Not Found." 尝试从 https://github.com/spacemeowx2/socat-windows/releases/latest/download/socat_x64.zip 下载... WARNING: 下载失败 (Invoke-WebRequest): Response status code does not indicate success: 404 (Not Found). 尝试备用下载方法 (WebClient)... WARNING: 下载失败 (WebClient): Exception calling "DownloadFile" with "2" argument(s): "The remote server returned an error: (404) Not Found." Install-Socat: Line | 14 | $installedPath = Install-Socat | ~~~~~~~~~~~~~ | 所有下载源均失败。最后错误: Exception calling "DownloadFile" with "2" argument(s): "The remote server returned an error: (404) Not Found." 手动安装步骤: 1. 从以下链接下载最新版socat: https://github.com/spacemeowx2/socat-windows/releases 2. 解压到目录: E:\Program Files\Socat 3. 添加PATH环境变量: [Environment]::SetEnvironmentVariable('Path', $env:Path + ";E:\Program Files\Socat", 'Machine') 4. 重启PowerShell会话 Exception: Line | 16 | throw "socat安装失败,请检查错误日志" | ~~~~~~~~~~~~~~~~~~~~~~~~~ | socat安装失败,请检查错误日志 [PS7 20:49:01] C:\Users\Administrator\Desktop [master] > [PS7 20:49:01] C:\Users\Administrator\Desktop [master] > # 3. 测试隧道 [PS7 20:49:01] C:\Users\Administrator\Desktop [master] > curl "http://localhost:$($tunnel.Port)" -UseBasicParsing Enter proxy password for user 'seBasicParsing':
最新发布
09-07
WARNING: Enabling and disabling experimental features do not take effect until next start of PowerShell. WARNING: Enabling and disabling experimental features do not take effect until next start of PowerShell. [PS7 19:25:05] C:\Users\Administrator\Desktop [master] > # 增强版 Install-Socat 函数(修复下载源问题) [PS7 19:25:13] C:\Users\Administrator\Desktop [master] > function Install-Socat { >> param( >> [Parameter(Mandatory = $false)] >> [string]$InstallDrive = "E:", >> >> [Parameter(Mandatory = $false)] >> [string]$InstallDir = "Program Files\Socat" >> ) >> >> # 1. 规范化路径处理 >> $fullPath = [System.IO.Path]::GetFullPath("$InstallDrive\$InstallDir").TrimEnd('\') >> >> # 2. 验证文件系统权限 >> if (-not ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) { >> Write-Warning "需要管理员权限安装程序" >> return $null >> } >> >> # 3. 检查现有安装 >> $existingPath = (Get-Command socat -ErrorAction SilentlyContinue | >> Select-Object -ExpandProperty Source -First 1) ?? $null >> >> if ($existingPath) { >> Write-Host "已安装于: $existingPath" -ForegroundColor Green >> return $existingPath >> } >> >> # 4. 创建安装目录 >> try { >> if (-not (Test-Path $fullPath)) { >> $null = New-Item -Path $fullPath -ItemType Directory -Force >> } >> } catch { >> Write-Error "创建目录失败: $($_.Exception.Message)" >> return $null >> } >> >> # 5. 文件下载(更新有效的下载源) >> $tempFile = Join-Path $env:TEMP "socat-win64.zip" >> $downloadUrls = @( >> # 官方镜像源 >> "https://github.com/portapps/socat-portable/releases/download/1.7.4.4/socat-1.7.4.4-win64.zip", >> "https://downloads.sourceforge.net/project/unix-utils/socat/1.7.4.4/socat-1.7.4.4-win64.zip?ts=$(Get-Date -UFormat %s)", >> >> # 备用镜像源 >> "https://github.com/portapps/socat-portable/releases/download/1.7.4.4/socat-1.7.4.4-win64.zip", >> "https://cfhcable.dl.sourceforge.net/project/unix-utils/socat/1.7.4.4/socat-1.7.4.4-win64.zip", >> "https://altushost-swe.dl.sourceforge.net/project/unix-utils/socat/1.7.4.4/socat-1.7.4.4-win64.zip" >> ) >> >> $validDownload = $false >> $lastError = $null >> >> foreach ($downloadUrl in $downloadUrls) { >> try { >> # 清除旧下载 >> if (Test-Path $tempFile) { >> Remove-Item $tempFile -Force -ErrorAction SilentlyContinue >> } >> >> # 下载文件 >> Write-Host "尝试从 $downloadUrl 下载..." -ForegroundColor Cyan >> $ProgressPreference = 'SilentlyContinue' >> >> try { >> Invoke-WebRequest $downloadUrl -OutFile $tempFile -UseBasicParsing -RetryIntervalSec 3 -ErrorAction Stop >> } catch { >> $lastError = $_.Exception.Message >> Write-Warning "下载失败 ($downloadUrl): $lastError" >> continue >> } >> >> # 验证文件大小(最小1MB) >> $fileInfo = Get-Item $tempFile -ErrorAction Stop >> if ($fileInfo.Length -lt 1MB) { >> $lastError = "文件过小 ($([math]::Round($fileInfo.Length/1KB)) KB)" >> Write-Warning "文件校验失败: $lastError" >> continue >> } >> >> # 验证ZIP文件完整性 >> try { >> Add-Type -AssemblyName System.IO.Compression.FileSystem -ErrorAction Stop >> $archive = [System.IO.Compression.ZipFile]::OpenRead($tempFile) >> $entryCount = $archive.Entries.Count >> $archive.Dispose() >> >> if ($entryCount -eq 0) { >> $lastError = "空压缩包" >> Write-Warning "文件校验失败: $lastError" >> continue >> } >> >> $validDownload = $true >> Write-Host "成功下载并验证: $downloadUrl" -ForegroundColor Green >> break >> } catch { >> $lastError = $_.Exception.Message >> Write-Warning "文件校验失败: $lastError" >> } >> } catch { >> $lastError = $_.Exception.Message >> Write-Warning "下载过程中出错: $lastError" >> } finally { >> $ProgressPreference = 'Continue' >> } >> } >> >> if (-not $validDownload) { >> Write-Error "所有下载源均失败。最后错误: $lastError" >> Write-Host @" >> 无法自动下载socat。请手动执行以下操作: >> 1. 从以下链接下载socat: >> https://github.com/portapps/socat-portable/releases >> 2. 解压到: $fullPath >> 3. 将以下路径添加到系统PATH环境变量: >> $fullPath >> "@ -ForegroundColor Yellow >> return $null >> } >> >> # 6. 解压缩 >> try { >> # 确保目标目录存在 >> if (-not (Test-Path $fullPath)) { >> $null = New-Item -Path $fullPath -ItemType Directory -Force >> } >> >> # 使用.NET方法解压 >> Add-Type -AssemblyName System.IO.Compression.FileSystem >> [System.IO.Compression.ZipFile]::ExtractToDirectory($tempFile, $fullPath) >> >> $socatExe = Join-Path $fullPath "socat.exe" >> >> if (-not (Test-Path $socatExe -PathType Leaf)) { >> throw "解压后未找到 socat.exe" >> } >> } catch { >> Write-Error "解压失败: $($_.Exception.Message)" >> return $null >> } >> >> # 7. 环境变量更新 >> $currentPath = [Environment]::GetEnvironmentVariable("Path", "Machine") >> if ($currentPath -notlike "*$fullPath*") { >> $newPath = $currentPath + ";$fullPath" >> [Environment]::SetEnvironmentVariable("Path", $newPath, "Machine") >> } >> >> # 8. 更新当前会话PATH >> $env:Path += ";$fullPath" >> >> # 9. 返回完整路径 >> if (Test-Path $socatExe) { >> Write-Host "socat 安装成功: $socatExe" -ForegroundColor Green >> return $socatExe.ToString() >> } else { >> Write-Error "安装后文件验证失败" >> return $null >> } >> } [PS7 19:25:14] C:\Users\Administrator\Desktop [master] > [PS7 19:25:14] C:\Users\Administrator\Desktop [master] > # 增强版 New-TcpTunnel 函数(保持不变) [PS7 19:25:14] C:\Users\Administrator\Desktop [master] > function New-TcpTunnel { >> param( >> [int]$LocalPort = 8443, >> [string]$RemoteHost = "google.com", >> [int]$RemotePort = 443, >> [string]$SocatPath = $null >> ) >> >> # 1. 获取socat路径 >> $socatBinary = if ($SocatPath -and (Test-Path $SocatPath)) { >> $SocatPath.ToString() >> } else { >> $installedPath = Install-Socat >> if (-not $installedPath) { >> throw "socat安装失败" >> } >> $installedPath.ToString() >> } >> >> # 2. 创建日志文件 >> $logTime = Get-Date -Format "yyyyMMdd-HHmmss" >> $stdOutFile = Join-Path $env:TEMP "socat-$LocalPort-$logTime-out.log" >> $stdErrFile = Join-Path $env:TEMP "socat-$LocalPort-$logTime-err.log" >> >> # 3. 启动进程 >> try { >> $processArgs = @{ >> FilePath = $socatBinary >> ArgumentList = "TCP-LISTEN:$LocalPort,fork,reuseaddr TCP:$($RemoteHost):$RemotePort" >> NoNewWindow = $true >> RedirectStandardOutput = $stdOutFile >> RedirectStandardError = $stdErrFile >> PassThru = $true >> } >> >> $process = Start-Process @processArgs >> } catch { >> Write-Error "启动socat失败: $($_.Exception.Message)" >> if (Test-Path $stdErrFile) { >> Write-Warning "错误日志内容: $(Get-Content $stdErrFile -Raw)" >> } >> throw >> } >> >> # 4. 验证端口监听 >> $portActive = $false >> 1..5 | ForEach-Object { >> Start-Sleep -Seconds 1 >> if (-not $portActive) { >> $portStatus = Get-NetTCPConnection -LocalPort $LocalPort -ErrorAction SilentlyContinue >> $portActive = [bool]$portStatus >> } >> } >> >> if (-not $portActive) { >> Write-Warning "端口 $LocalPort 状态: 未监听" >> if (Test-Path $stdErrFile) { >> Write-Warning "错误日志: $(Get-Content $stdErrFile -Raw)" >> } >> throw "隧道创建失败,端口 $LocalPort 未监听" >> } >> >> # 5. 返回进程信息 >> return [PSCustomObject]@{ >> Process = $process >> Port = $LocalPort >> StdOutLog = $stdOutFile >> StdErrLog = $stdErrFile >> } >> } [PS7 19:25:14] C:\Users\Administrator\Desktop [master] > # 测试安装函数 [PS7 19:25:20] C:\Users\Administrator\Desktop [master] > $socatPath = Install-Socat -Verbose 尝试从 https://github.com/portapps/socat-portable/releases/download/1.7.4.4/socat-1.7.4.4-win64.zip 下载... VERBOSE: Requested HTTP/1.1 GET with 0-byte payload VERBOSE: Received HTTP/1.1 9-byte response of content type text/plain WARNING: 下载失败 (https://github.com/portapps/socat-portable/releases/download/1.7.4.4/socat-1.7.4.4-win64.zip): Response status code does not indicate success: 404 (Not Found). 尝试从 https://downloads.sourceforge.net/project/unix-utils/socat/1.7.4.4/socat-1.7.4.4-win64.zip?ts=1757157921 下载... VERBOSE: Requested HTTP/1.1 GET with 0-byte payload VERBOSE: Received HTTP/1.1 response of content type text/html of unknown size VERBOSE: File Name: socat-win64.zip WARNING: 文件校验失败: 文件过小 (102 KB) 尝试从 https://github.com/portapps/socat-portable/releases/download/1.7.4.4/socat-1.7.4.4-win64.zip 下载... VERBOSE: Requested HTTP/1.1 GET with 0-byte payload VERBOSE: Received HTTP/1.1 9-byte response of content type text/plain WARNING: 下载失败 (https://github.com/portapps/socat-portable/releases/download/1.7.4.4/socat-1.7.4.4-win64.zip): Response status code does not indicate success: 404 (Not Found). 尝试从 https://cfhcable.dl.sourceforge.net/project/unix-utils/socat/1.7.4.4/socat-1.7.4.4-win64.zip 下载... VERBOSE: Requested HTTP/1.1 GET with 0-byte payload WARNING: 下载失败 (https://cfhcable.dl.sourceforge.net/project/unix-utils/socat/1.7.4.4/socat-1.7.4.4-win64.zip): 由于连接方在一段时间后没有正确答复或连接的主机没有反应,连接尝试失败。 (cfhcable.dl.sourceforge.net:443) 尝试从 https://altushost-swe.dl.sourceforge.net/project/unix-utils/socat/1.7.4.4/socat-1.7.4.4-win64.zip 下载... VERBOSE: Requested HTTP/1.1 GET with 0-byte payload VERBOSE: Received HTTP/1.1 response of content type text/html of unknown size VERBOSE: File Name: socat-win64.zip WARNING: 文件校验失败: 文件过小 (102 KB) Install-Socat: 所有下载源均失败。最后错误: 文件过小 (102 KB) 无法自动下载socat。请手动执行以下操作: 1. 从以下链接下载socat: https://github.com/portapps/socat-portable/releases 2. 解压到: E:\Program Files\Socat 3. 将以下路径添加到系统PATH环境变量: E:\Program Files\Socat [PS7 19:25:58] C:\Users\Administrator\Desktop [master] > [PS7 19:25:58] C:\Users\Administrator\Desktop [master] > # 验证安装 [PS7 19:25:58] C:\Users\Administrator\Desktop [master] > if ($socatPath) { >> socat -V >> Write-Host "socat 安装成功" -ForegroundColor Green >> } [PS7 19:25:58] C:\Users\Administrator\Desktop [master] > # 创建到HTTP服务的隧道 [PS7 19:26:10] C:\Users\Administrator\Desktop [master] > $tunnel = New-TcpTunnel -LocalPort 8080 -RemoteHost "example.com" -RemotePort 80 尝试从 https://github.com/portapps/socat-portable/releases/download/1.7.4.4/socat-1.7.4.4-win64.zip 下载... WARNING: 下载失败 (https://github.com/portapps/socat-portable/releases/download/1.7.4.4/socat-1.7.4.4-win64.zip): Response status code does not indicate success: 404 (Not Found). 尝试从 https://downloads.sourceforge.net/project/unix-utils/socat/1.7.4.4/socat-1.7.4.4-win64.zip?ts=1757157971 下载... WARNING: 文件校验失败: 文件过小 (102 KB) 尝试从 https://github.com/portapps/socat-portable/releases/download/1.7.4.4/socat-1.7.4.4-win64.zip 下载... WARNING: 下载失败 (https://github.com/portapps/socat-portable/releases/download/1.7.4.4/socat-1.7.4.4-win64.zip): Response status code does not indicate success: 404 (Not Found). 尝试从 https://cfhcable.dl.sourceforge.net/project/unix-utils/socat/1.7.4.4/socat-1.7.4.4-win64.zip 下载... WARNING: 下载失败 (https://cfhcable.dl.sourceforge.net/project/unix-utils/socat/1.7.4.4/socat-1.7.4.4-win64.zip): 由于连接方在一段时间后没有正确答复或连接的主机没有反应,连接尝试失败。 (cfhcable.dl.sourceforge.net:443) 尝试从 https://altushost-swe.dl.sourceforge.net/project/unix-utils/socat/1.7.4.4/socat-1.7.4.4-win64.zip 下载... WARNING: 文件校验失败: 文件过小 (102 KB) Install-Socat: Line | 13 | $installedPath = Install-Socat | ~~~~~~~~~~~~~ | 所有下载源均失败。最后错误: 文件过小 (102 KB) 无法自动下载socat。请手动执行以下操作: 1. 从以下链接下载socat: https://github.com/portapps/socat-portable/releases 2. 解压到: E:\Program Files\Socat 3. 将以下路径添加到系统PATH环境变量: E:\Program Files\Socat Exception: Line | 15 | throw "socat安装失败" | ~~~~~~~~~~~~~~~~~ | socat安装失败 [PS7 19:26:48] C:\Users\Administrator\Desktop [master] > [PS7 19:26:48] C:\Users\Administrator\Desktop [master] > # 测试隧道 [PS7 19:26:48] C:\Users\Administrator\Desktop [master] > Start-Process "http://localhost:$($tunnel.Port)" [PS7 19:26:48] C:\Users\Administrator\Desktop [master] > [PS7 19:26:48] C:\Users\Administrator\Desktop [master] > # 监控日志 [PS7 19:26:48] C:\Users\Administrator\Desktop [master] > Get-Content $tunnel.StdErrLog -Wait -Tail 10 Get-Content: Cannot bind argument to parameter 'Path' because it is null. [PS7 19:26:48] C:\Users\Administrator\Desktop [master] > $cacheFile = "C:\ProgramData\socat-cache\socat-win64.zip" [PS7 19:27:07] C:\Users\Administrator\Desktop [master] > if (Test-Path $cacheFile) { >> Copy-Item $cacheFile $tempFile >> $validDownload = $true >> } [PS7 19:27:07] C:\Users\Administrator\Desktop [master] >
09-07
WARNING: Enabling and disabling experimental features do not take effect until next start of PowerShell. WARNING: Enabling and disabling experimental features do not take effect until next start of PowerShell. [PS7 19:30:16] C:\Users\Administrator\Desktop [master] > # 增强版 Install-Socat 函数(修复下载源失效问题) [PS7 19:30:19] C:\Users\Administrator\Desktop [master] > function Install-Socat { >> param( >> [Parameter(Mandatory = $false)] >> [string]$InstallDrive = "E:", >> >> [Parameter(Mandatory = $false)] >> [string]$InstallDir = "Program Files\Socat" >> ) >> >> # 1. 规范化路径处理 >> $fullPath = [System.IO.Path]::GetFullPath("$InstallDrive\$InstallDir").TrimEnd('\') >> >> # 2. 验证文件系统权限 >> if (-not ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) { >> Write-Warning "需要管理员权限安装程序" >> return $null >> } >> >> # 3. 检查现有安装 >> $existingPath = (Get-Command socat -ErrorAction SilentlyContinue | >> Select-Object -ExpandProperty Source -First 1) ?? $null >> >> if ($existingPath) { >> Write-Host "已安装于: $existingPath" -ForegroundColor Green >> return $existingPath >> } >> >> # 4. 创建安装目录 >> try { >> if (-not (Test-Path $fullPath)) { >> $null = New-Item -Path $fullPath -ItemType Directory -Force >> } >> } catch { >> Write-Error "创建目录失败: $($_.Exception.Message)" >> return $null >> } >> >> # 5. 文件下载(更新有效的下载源) >> $tempFile = Join-Path $env:TEMP "socat-win64.zip" >> >> # 更新为有效的下载源(GitHub官方镜像) >> $downloadUrls = @( >> "https://github.com/spacemeowx2/socat-windows/releases/download/1.7.4.4/socat_x64.zip", >> "https://github.com/spacemeowx2/socat-windows/releases/download/1.7.4.4/socat_x64.zip", >> "https://github.com/spacemeowx2/socat-windows/releases/download/1.7.4.4/socat_x64.zip" >> ) >> >> $validDownload = $false >> $lastError = $null >> >> # 尝试使用不同方法下载 >> :downloadLoop foreach ($downloadUrl in $downloadUrls) { >> try { >> Write-Host "尝试从 $downloadUrl 下载..." -ForegroundColor Cyan >> >> # 方法1:使用Invoke-WebRequest >> try { >> $ProgressPreference = 'SilentlyContinue' >> Invoke-WebRequest $downloadUrl -OutFile $tempFile -UseBasicParsing -RetryIntervalSec 3 -ErrorAction Stop >> >> # 验证文件大小(最小500KB) >> $fileInfo = Get-Item $tempFile -ErrorAction Stop >> if ($fileInfo.Length -lt 500KB) { >> $lastError = "文件过小 ($([math]::Round($fileInfo.Length/1KB)) KB)" >> Write-Warning "文件校验失败: $lastError" >> continue >> } >> >> $validDownload = $true >> Write-Host "成功下载: $downloadUrl" -ForegroundColor Green >> break downloadLoop >> } catch { >> $lastError = $_.Exception.Message >> Write-Warning "下载失败 (方法1): $lastError" >> } >> >> # 方法2:使用.NET WebClient(备选方法) >> try { >> Write-Host "尝试备选下载方法..." -ForegroundColor Yellow >> $webClient = New-Object System.Net.WebClient >> $webClient.DownloadFile($downloadUrl, $tempFile) >> >> # 验证文件大小 >> $fileInfo = Get-Item $tempFile -ErrorAction Stop >> if ($fileInfo.Length -lt 500KB) { >> $lastError = "文件过小 ($([math]::Round($fileInfo.Length/1KB)) KB)" >> Write-Warning "文件校验失败: $lastError" >> continue >> } >> >> $validDownload = $true >> Write-Host "备选下载方法成功" -ForegroundColor Green >> break downloadLoop >> } catch { >> $lastError = $_.Exception.Message >> Write-Warning "下载失败 (方法2): $lastError" >> } >> } finally { >> $ProgressPreference = 'Continue' >> } >> } >> >> # 如果所有下载源都失败,提供替代安装方案 >> if (-not $validDownload) { >> Write-Error "所有下载源均失败。最后错误: $lastError" >> >> # 替代方案1:使用winget安装(如果可用) >> if (Get-Command winget -ErrorAction SilentlyContinue) { >> Write-Host "尝试使用winget安装socat..." -ForegroundColor Cyan >> try { >> winget install --id spacemeowx2.socat -e >> $wingetPath = (Get-Command socat).Source >> if ($wingetPath) { >> Write-Host "winget安装成功: $wingetPath" -ForegroundColor Green >> return $wingetPath >> } >> } catch { >> Write-Warning "winget安装失败: $($_.Exception.Message)" >> } >> } >> >> # 替代方案2:提供手动安装指南 >> Write-Host @" >> 无法自动下载socat。请手动执行以下操作: >> 1. 从以下链接下载socat: >> https://github.com/spacemeowx2/socat-windows/releases >> 2. 解压到: $fullPath >> 3. 将以下路径添加到系统PATH环境变量: >> $fullPath >> (命令: `$env:Path += `";$fullPath`"`) >> "@ -ForegroundColor Yellow >> >> # 尝试打开下载页面 >> try { >> Start-Process "https://github.com/spacemeowx2/socat-windows/releases" >> } catch { >> Write-Warning "无法打开浏览器" >> } >> >> return $null >> } >> >> # 6. 解压缩 >> try { >> # 使用内置Expand-Archive解压(更可靠) >> Expand-Archive -Path $tempFile -DestinationPath $fullPath -Force >> >> # 查找socat.exe(支持不同目录结构) >> $socatExe = Get-ChildItem -Path $fullPath -Filter "socat.exe" -Recurse | >> Select-Object -First 1 -ExpandProperty FullName >> >> if (-not $socatExe) { >> throw "解压后未找到 socat.exe" >> } >> >> # 如果不在根目录,移动到根目录 >> if ($socatExe -ne (Join-Path $fullPath "socat.exe")) { >> Move-Item -Path $socatExe -Destination $fullPath -Force >> $socatExe = Join-Path $fullPath "socat.exe" >> } >> } catch { >> Write-Error "解压失败: $($_.Exception.Message)" >> return $null >> } >> >> # 7. 环境变量更新 >> $currentPath = [Environment]::GetEnvironmentVariable("Path", "Machine") >> if ($currentPath -notlike "*$fullPath*") { >> $newPath = $currentPath + ";$fullPath" >> [Environment]::SetEnvironmentVariable("Path", $newPath, "Machine") >> } >> >> # 8. 更新当前会话PATH >> $env:Path += ";$fullPath" >> >> # 9. 返回完整路径 >> if (Test-Path $socatExe) { >> Write-Host "socat 安装成功: $socatExe" -ForegroundColor Green >> return $socatExe >> } else { >> Write-Error "安装后文件验证失败" >> return $null >> } >> } [PS7 19:30:23] C:\Users\Administrator\Desktop [master] > [PS7 19:30:23] C:\Users\Administrator\Desktop [master] > # 增强版 New-TcpTunnel 函数(添加超时和重试机制) [PS7 19:30:23] C:\Users\Administrator\Desktop [master] > function New-TcpTunnel { >> param( >> [int]$LocalPort = 8443, >> [string]$RemoteHost = "google.com", >> [int]$RemotePort = 443, >> [string]$SocatPath = $null, >> [int]$TimeoutSeconds = 10 >> ) >> >> # 1. 获取socat路径 >> $socatBinary = if ($SocatPath -and (Test-Path $SocatPath)) { >> $SocatPath >> } else { >> $installedPath = Install-Socat >> if (-not $installedPath) { >> throw "socat安装失败" >> } >> $installedPath >> } >> >> # 2. 创建日志文件 >> $logTime = Get-Date -Format "yyyyMMdd-HHmmss" >> $stdOutFile = Join-Path $env:TEMP "socat-$LocalPort-$logTime-out.log" >> $stdErrFile = Join-Path $env:TEMP "socat-$LocalPort-$logTime-err.log" >> >> # 3. 启动进程 >> try { >> $processArgs = @{ >> FilePath = $socatBinary >> ArgumentList = "TCP-LISTEN:$LocalPort,fork,reuseaddr TCP:$($RemoteHost):$RemotePort" >> NoNewWindow = $true >> RedirectStandardOutput = $stdOutFile >> RedirectStandardError = $stdErrFile >> PassThru = $true >> } >> >> $process = Start-Process @processArgs >> } catch { >> Write-Error "启动socat失败: $($_.Exception.Message)" >> if (Test-Path $stdErrFile) { >> Write-Warning "错误日志内容: $(Get-Content $stdErrFile -Raw)" >> } >> throw >> } >> >> # 4. 验证端口监听(带超时机制) >> $portActive = $false >> $startTime = Get-Date >> while (-not $portActive -and ((Get-Date) - $startTime).TotalSeconds -lt $TimeoutSeconds) { >> Start-Sleep -Seconds 1 >> $portStatus = Get-NetTCPConnection -LocalPort $LocalPort -ErrorAction SilentlyContinue >> $portActive = [bool]$portStatus >> >> # 检查进程是否已退出 >> if ($process.HasExited) { >> if (Test-Path $stdErrFile) { >> $errorContent = Get-Content $stdErrFile -Raw >> Write-Error "进程意外退出: $errorContent" >> } >> throw "socat进程已退出" >> } >> } >> >> if (-not $portActive) { >> Write-Warning "端口 $LocalPort 状态: 未监听" >> if (Test-Path $stdErrFile) { >> Write-Warning "错误日志: $(Get-Content $stdErrFile -Raw)" >> } >> throw "隧道创建失败,端口 $LocalPort 未监听" >> } >> >> # 5. 返回进程信息 >> return [PSCustomObject]@{ >> Process = $process >> Port = $LocalPort >> StdOutLog = $stdOutFile >> StdErrLog = $stdErrFile >> } >> } [PS7 19:30:23] C:\Users\Administrator\Desktop [master] > # 1. 安装socat(使用更新后的源) [PS7 19:30:40] C:\Users\Administrator\Desktop [master] > $socatPath = Install-Socat -InstallDrive "D:" -InstallDir "NetTools" 尝试从 https://github.com/spacemeowx2/socat-windows/releases/download/1.7.4.4/socat_x64.zip 下载... WARNING: 下载失败 (方法1): Response status code does not indicate success: 404 (Not Found). 尝试备选下载方法... WARNING: 下载失败 (方法2): Exception calling "DownloadFile" with "2" argument(s): "The remote server returned an error: (404) Not Found." 尝试从 https://github.com/spacemeowx2/socat-windows/releases/download/1.7.4.4/socat_x64.zip 下载... WARNING: 下载失败 (方法1): Response status code does not indicate success: 404 (Not Found). 尝试备选下载方法... WARNING: 下载失败 (方法2): Exception calling "DownloadFile" with "2" argument(s): "The remote server returned an error: (404) Not Found." 尝试从 https://github.com/spacemeowx2/socat-windows/releases/download/1.7.4.4/socat_x64.zip 下载... WARNING: 下载失败 (方法1): Response status code does not indicate success: 404 (Not Found). 尝试备选下载方法... WARNING: 下载失败 (方法2): Exception calling "DownloadFile" with "2" argument(s): "The remote server returned an error: (404) Not Found." Install-Socat: 所有下载源均失败。最后错误: Exception calling "DownloadFile" with "2" argument(s): "The remote server returned an error: (404) Not Found." 尝试使用winget安装socat... Get-Command: Line | 112 | $wingetPath = (Get-Command socat).Source | ~~~~~~~~~~~~~~~~~ | The term 'socat' is not recognized as a name of a cmdlet, function, script file, or executable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. 无法自动下载socat。请手动执行以下操作: 1. 从以下链接下载socat: https://github.com/spacemeowx2/socat-windows/releases 2. 解压到: D:\NetTools 3. 将以下路径添加到系统PATH环境变量: D:\NetTools (命令: $env:Path += ";D:\NetTools") [PS7 19:31:13] C:\Users\Administrator\Desktop [master] > [PS7 19:31:13] C:\Users\Administrator\Desktop [master] > # 2. 创建到HTTP服务的隧道 [PS7 19:31:13] C:\Users\Administrator\Desktop [master] > $tunnel = New-TcpTunnel -LocalPort 8080 -RemoteHost "example.com" -RemotePort 80 -TimeoutSeconds 15 尝试从 https://github.com/spacemeowx2/socat-windows/releases/download/1.7.4.4/socat_x64.zip 下载... WARNING: 下载失败 (方法1): Response status code does not indicate success: 404 (Not Found). 尝试备选下载方法... WARNING: 下载失败 (方法2): Exception calling "DownloadFile" with "2" argument(s): "The remote server returned an error: (404) Not Found." 尝试从 https://github.com/spacemeowx2/socat-windows/releases/download/1.7.4.4/socat_x64.zip 下载... WARNING: 下载失败 (方法1): Response status code does not indicate success: 404 (Not Found). 尝试备选下载方法... WARNING: 下载失败 (方法2): Exception calling "DownloadFile" with "2" argument(s): "The remote server returned an error: (404) Not Found." 尝试从 https://github.com/spacemeowx2/socat-windows/releases/download/1.7.4.4/socat_x64.zip 下载... WARNING: 下载失败 (方法1): Response status code does not indicate success: 404 (Not Found). 尝试备选下载方法... WARNING: 下载失败 (方法2): Exception calling "DownloadFile" with "2" argument(s): "The remote server returned an error: (404) Not Found." Install-Socat: Line | 14 | $installedPath = Install-Socat | ~~~~~~~~~~~~~ | 所有下载源均失败。最后错误: Exception calling "DownloadFile" with "2" argument(s): "The remote server returned an error: (404) Not Found." 尝试使用winget安装socat... Get-Command: Line | 112 | $wingetPath = (Get-Command socat).Source | ~~~~~~~~~~~~~~~~~ | The term 'socat' is not recognized as a name of a cmdlet, function, script file, or executable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. 无法自动下载socat。请手动执行以下操作: 1. 从以下链接下载socat: https://github.com/spacemeowx2/socat-windows/releases 2. 解压到: E:\Program Files\Socat 3. 将以下路径添加到系统PATH环境变量: E:\Program Files\Socat (命令: $env:Path += ";E:\Program Files\Socat") New-TcpTunnel: 启动socat失败: Cannot convert 'System.Object[]' to the type 'System.String' required by parameter 'FilePath'. Specified method is not supported. Start-Process: Line | 37 | $process = Start-Process @processArgs | ~~~~~~~~~~~~ | Cannot convert 'System.Object[]' to the type 'System.String' required by parameter 'FilePath'. Specified method is not supported. [PS7 19:31:39] C:\Users\Administrator\Desktop [master] > [PS7 19:31:39] C:\Users\Administrator\Desktop [master] > # 3. 测试隧道 [PS7 19:31:39] C:\Users\Administrator\Desktop [master] > curl -v "http://localhost:$($tunnel.Port)" * Host localhost:80 was resolved. * IPv6: ::1 * IPv4: 127.0.0.1 * Trying [::1]:80... * Trying 127.0.0.1:80... * connect to ::1 port 80 from :: port 54290 failed: Connection refused * connect to 127.0.0.1 port 80 from 0.0.0.0 port 54296 failed: Connection refused * Failed to connect to localhost port 80 after 2215 ms: Could not connect to server * closing connection #0 [PS7 19:31:41] C:\Users\Administrator\Desktop [master] > [PS7 19:31:41] C:\Users\Administrator\Desktop [master] > # 4. 监控日志(实时查看) [PS7 19:31:41] C:\Users\Administrator\Desktop [master] > Get-Content $tunnel.StdErrLog -Wait -Tail 10 Get-Content: Cannot bind argument to parameter 'Path' because it is null. [PS7 19:31:41] C:\Users\Administrator\Desktop [master] > [PS7 19:31:42] C:\Users\Administrator\Desktop [master] > # 5. 使用内置网页测试 [PS7 19:31:42] C:\Users\Administrator\Desktop [master] > Start-Process "http://localhost:$($tunnel.Port)" [PS7 19:31:42] C:\Users\Administrator\Desktop [master] >
09-07
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值