You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

寻求可替代Unix工具Ethtool的Windows以太网自动协商工具及对应命令行实现方案

Hey there! Let's break down how to replicate that Unix ethtool script's functionality on Windows—since Windows doesn't have a direct drop-in replacement for ethtool, we'll use built-in tools to get the job done.

Windows Tools to Replace ethtool for Ethernet Autonegotiation

First, the two go-to built-in tools for managing Ethernet interface settings on Windows are:

  • netsh: The classic command-line utility that works in both Command Prompt and PowerShell. It's been around forever and handles most basic network config tasks.
  • PowerShell Cmdlets: Get-NetAdapter and Set-NetAdapterAdvancedProperty are more modern, granular tools that make it easier to target specific adapters and properties.

Replicating Your Unix Script's Behavior

Your original script loops through all network interfaces, turns on autonegotiation for each, and prints a confirmation message. Here's how to do this in Windows:

Option 1: Command Prompt (CMD) Script

CMD doesn't handle interface loops as smoothly as Unix shells, but we can hack together a working script with netsh and a for loop:

@echo off
setlocal enabledelayedexpansion

:: Loop through all Ethernet interfaces (skip non-physical/loopback adapters)
for /f "tokens=2 delims=:" %%i in ('netsh interface show interface ^| findstr /i "ethernet"') do (
    :: Trim leading whitespace from the interface name
    set "iface=%%i"
    set "iface=!iface:~1!"
    echo Turning on autonegotiation for !iface!
    :: Enable link-level autonegotiation (speed/duplex)
    netsh interface set interface "!iface!" autonegotiate=enabled
    :: If you also need to enable IP autoconfiguration (DHCP), add this line:
    :: netsh interface ipv4 set interface "!iface!" autoconfiguration=enabled
)
endlocal

Heads up: The exact property name might vary depending on your network adapter's driver. If autonegotiate=enabled doesn't work, check your adapter's advanced properties in Control Panel to find the correct parameter name, then adjust the netsh command accordingly.

Option 2: PowerShell Script (More Reliable)

PowerShell is way better at handling network adapters, so this is the recommended approach:

# Grab all physical Ethernet adapters (skips loopback and virtual adapters)
$ethernetAdapters = Get-NetAdapter | Where-Object { $_.PhysicalMediaType -eq "802.3" }

foreach ($adapter in $ethernetAdapters) {
    Write-Host "Enabling autonegotiation on $($adapter.Name)"
    # Turn on link-level autonegotiation (speed/duplex)
    Set-NetAdapterAdvancedProperty -Name $adapter.Name -DisplayName "Auto Negotiation" -DisplayValue "Enabled"
    # If you need to enable DHCP for IP config, uncomment this line:
    # Set-NetIPInterface -InterfaceAlias $adapter.Name -Dhcp Enabled
}

Pro tip: If "Auto Negotiation" isn't the right display name for your adapter, run Get-NetAdapterAdvancedProperty -Name $adapter.Name to list all available properties for your hardware, then use the correct name from that output.

Important Notes

  • Run as Admin: Both scripts need to be executed with Administrator privileges—otherwise, you'll hit access denied errors when trying to modify interface settings.
  • Adapter Compatibility: Some older network adapters might not support autonegotiation, or might use a different property name (like "Speed & Duplex" set to "Auto"). Always double-check your adapter's specific settings if the commands don't work.

内容的提问来源于stack exchange,提问作者sanjanaraju_inde

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.29 08:02:31