[Um artigo para entender] [WIN] [CMD] arranjo de uso netsh

Netsh é um utilitário de script de linha de comando que permite exibir ou modificar a configuração de rede do computador em execução no momento. Você pode executar comandos Netsh digitando-os no prompt netsh e pode usar comandos Netsh em arquivos ou scripts em lote. Você pode usar comandos netsh para configurar computadores remotos e locais.

Netsh também fornece um recurso de script que permite executar um conjunto de comandos em um computador especificado no modo de lote. Você pode usar o Netsh para salvar scripts de configuração em arquivos de texto para arquivamento ou para ajudá-lo a configurar outros computadores.

1. Como usar corretamentenetsh

  1. Quando esquecemos os comandos relevantes do netsh, podemos usar diretamente a função de ajuda que vem com o netsh e podemos ver alguns comandos que podem ser usados.
netsh /?

C:\Users\ming Ming>netsh /?

Usage: netsh [-a AliasFile] [-c Context] [-r RemoteMachine] [-u [DomainName\]UserName] [-p Password | *]
             [Command | -f ScriptFile]

The following commands are available:

Commands in this context:
?              - Displays a list of commands.
add            - Adds a configuration entry to a list of entries.
advfirewall    - Changes to the `netsh advfirewall' context.
bridge         - Changes to the `netsh bridge' context.
delete         - Deletes a configuration entry from a list of entries.
dhcpclient     - Changes to the `netsh dhcpclient' context.
dnsclient      - Changes to the `netsh dnsclient' context.
dump           - Displays a configuration script.
exec           - Runs a script file.
firewall       - Changes to the `netsh firewall' context.
help           - Displays a list of commands.
http           - Changes to the `netsh http' context.
interface      - Changes to the `netsh interface' context.
ipsec          - Changes to the `netsh ipsec' context.
lan            - Changes to the `netsh lan' context.
mbn            - Changes to the `netsh mbn' context.
namespace      - Changes to the `netsh namespace' context.
netio          - Changes to the `netsh netio' context.
nlm            - Changes to the `netsh nlm' context.
p2p            - Changes to the `netsh p2p' context.
ras            - Changes to the `netsh ras' context.
rpc            - Changes to the `netsh rpc' context.
set            - Updates configuration settings.
show           - Displays information.
trace          - Changes to the `netsh trace' context.
wcn            - Changes to the `netsh wcn' context.
wfp            - Changes to the `netsh wfp' context.
winhttp        - Changes to the `netsh winhttp' context.
winsock        - Changes to the `netsh winsock' context.
wlan           - Changes to the `netsh wlan' context.

The following sub-contexts are available:
 advfirewall bridge dhcpclient dnsclient firewall http interface ipsec lan mbn namespace netio nlm p2p ras rpc trace wcn wfp winhttp winsock wlan

To view help for a command, type the command, followed by a space, and then
 type ?.
  1. Depois de saber quais funções opcionais estão disponíveis, podemos inserir comandos secundários para executar as operações que realizaremos. Por exemplo, exibirei o status atual da conexão tcp da seguinte forma:

    $>netsh
    $netsh>int
    $netsh interface>ip
    $netsh interface ipv4>show tcpstats
    
    TCP Statistics
    ------------------------------------------------------
    Timeout Algorithm:                      Van Jacobson's Algorithm
    Minimum Timeout:                        5
    Maximum Timeout:                        4294967295
    Maximum Connections:                    Dynamic
    Active Opens:                           3971
    Passive Opens:                          556
    Attempts Failed:                        1017
    Established Resets:                     407
    Currently Established:                  34
    In Segments:                            202193
    Out Segments:                           149657
    Retransmitted Segments:                 0
    In Errors:                              0
    Out Resets:                             845
    Fastopen Active Opens:                  0
    Fastopen Passive Opens:                 0
    Fastopen Attempts Failed:               0
    Retransmits Of First SYN:               644
    Retransmits Of First SYN (Fastopen):    0
    

2. netshArranjo de comando

1. Exportar e importar script

  1. Exportar script de configuração:

    netsh -c interface ip dump > c:/interface.txt
    
  2. Importar script de configuração:

    netsh -f c:/interface.txt
    

2. Processamento em lote de endereços IP fixos

//SETIPDNS.bat (substitua "Conexão local" pelo nome da sua placa de rede, endereço IP específico, gateway, modifique você mesmo)

@echo off

echo 正在修改本机IP...

netsh interface ip set address name="本地连接" source=static 192.168.1.188  255.255.255.0 192.168.1.1 1

echo 正在添加本机主DNS...

netsh interface ip set dns "本地连接" static 18.0.0.10 primary

echo 正在添加本机副DNS...

netsh interface ip add dns "本地连接" 18.0.0.10

echo 设置完成...

echo 检查当前本机配置...

ipconfig /all

echo 导出配置脚本...

netsh -c interface ip dump

pause

3. Obtenha o IP automaticamente

@echo off

echo 正在修改本机IP...

netsh interface ip set address name="本地连接" source=dhcp

echo 正在添加本机主DNS...

netsh interface ip set dns "本地连接" dhcp

echo 设置完成...

echo 检查当前本机配置...

ipconfig /all

echo 导出配置脚本...

netsh -c interface ip dump

pause

4. uso netsh

  1. Ver configuração de rede

    netsh interface ip show {
          
          选项}
    
    {
          
          选项}可以是:
    address-显示IP地址配置。
    config-显示IP地址和更多信息。
    dns-显示DNS服务器地址。
    icmp-显示ICMP统计。
    interface-显示IP接口统计。
    ipaddress-显示当前IP地址。
    ipnet-显示IP的网络到媒体的映射。
    ipstats-显示IP统计。
    joins-显示加入的多播组。
    offload-显示卸载信息。
    tcpconn-显示TCP连接。
    tcpstats-显示TCP统计。
    udpconn-显示UDP连接。
    udpstats-显示UDP统计。
    wins-显示WINS服务器地址。
    
  2. Ver configuração de rede

    netsh interface ip show {
          
          选项}
    
    {
          
          选项}可以是:
    address-显示IP地址配置。
    config-显示IP地址和更多信息。
    dns-显示DNS服务器地址。
    icmp-显示ICMP统计。
    interface-显示IP接口统计。
    ipaddress-显示当前IP地址。
    ipnet-显示IP的网络到媒体的映射。
    ipstats-显示IP统计。
    joins-显示加入的多播组。
    offload-显示卸载信息。
    tcpconn-显示TCP连接。
    tcpstats-显示TCP统计。
    udpconn-显示UDP连接。
    udpstats-显示UDP统计。
    wins-显示WINS服务器地址。
    
  3. Configurar IP da interface/IP do gateway

    netsh interface ip set address "本地连接" static 10.1.2.90 255.255.255.0 10.1.2.254 1
    
  4. Configure a troca automática de endereço IP, endereço DNS e ganhe endereço

    netsh interface ip set address "本地连接" dhcp
    netsh interface ip set dns "本地连接" dhcp
    netsh interface ip set wins "本地连接" dhcp
    
  5. Configurar endereço IP estático, endereço DNS e endereço wins

    netsh interface ip set address "本地连接" static 10.1.2.90
    netsh interface ip set dns "本地连接" static 202.99.160.68
    netsh interface ip set wins "本地连接" static 10.1.2.200
    
  6. ver arquivo de configuração de rede

    C:>netsh -c interface dump
    
  7. Exportar arquivo de configuração de rede

    netsh -c interface dump > d:/1.txt
    
  8. Importar arquivos de configuração de rede

    netsh -f d:/1.txt
    netsh exec d:/2.txt 
    
  9. netsh configurar firewall
    Exibir, habilitar ou desabilitar o firewall do sistema

    # 查看防火墙的状态
    netsh firewall show state
    
    # 禁用系统防火墙
    netsh firewall set opmode disable
    
    # 启用防火墙
    netsh firewall set opmode enable
    

おすすめ

転載: blog.csdn.net/Fuel_Ming/article/details/123992944