下面是ai写的, 不行- function Test-WiredConnection {
- $pingResult = Test-Connection -ComputerName 8.8.8.8 -Count 1 -ErrorAction SilentlyContinue
- return $pingResult.StatusCode -eq 0
- }
-
- function Connect-Wifi {
- param (
- [string]$SSID,
- [string]$Password
- )
- $profileXml = @"
- <XML>
- <WLANProfile xmlns="http://www.microsoft.com/networking/WLAN/profile/v1">
- <name>$SSID</name>
- <SSIDConfig>
- <SSID>
- <name>$SSID</name>
- </SSID>
- </SSIDConfig>
- <connectionType>ESS</connectionType>
- <connectionMode>manual</connectionMode>
- <MSM>
- <security>
- <authEncryption>
- <authentication>WPA2PSK</authentication>
- <encryption>AES</encryption>
- <useOneX>false</useOneX>
- </authEncryption>
- <sharedKey>
- <keyType>passPhrase</keyType>
- <protected>false</protected>
- <keyMaterial>$Password</keyMaterial>
- </sharedKey>
- </security>
- </MSM>
- </WLANProfile>
- </XML>
- "@
- $profilePath = "$env:TEMP\$SSID.xml"
- $profileXml | Set-Content -Path $profilePath -Encoding UTF8
- netsh wlan add profile filename="$profilePath" > $null
- netsh wlan connect name=$SSID > $null
- }
-
- if (Test-WiredConnection) {
- Write-Host "Wired connection is active. Connecting to AAA..."
- Connect-Wifi -SSID "AAA" -Password "111"
- } else {
- Write-Host "Wired connection is inactive. Connecting to BBB..."
- Connect-Wifi -SSID "BBB" -Password "222"
- }
复制代码
|