• 配置DNS服务器IP


     1 #############################脚本功能及说明####################
     2 #该脚本用来在本地服务器上配置DNS服务器IP
     3 #创建时间:2014-10-22
     4 
     5 #########################定义函数#############################
     6 #定义函数:配置DNS
     7 #ConnectionID为网卡ID;$dnsservers为要配置的DNS服务器的IP列表
     8 function DNSConfig($ConnectionID,[array]$dnsservers)
     9     {
    10      #判断当前系统是2003(5),还是2008,在设置DNS服务器的时候所使用的命令不同
    11      If ((gwmi win32_operatingsystem).version.split(".")[0] -eq 5)
    12         {
    13          netsh.exe interface ip set dns "$ConnectionID" static $dnsservers[0] primary
    14          $dnsservers[1..$dnsservers.count] | % { netsh.exe interface ip add dns "$ConnectionID" $_ }
    15         }
    16      Else 
    17        {
    18         netsh.exe interface ip set dnsservers "$ConnectionID" static $dnsservers[0] primary validate=no
    19         $dnsservers[1..$dnsservers.count] | % { netsh.exe interface ip add dnsservers "$ConnectionID" $_ validate=no } 
    20        }
    21     }
    22 
    23 ################脚本开始######################################################################
    24 $index = (gwmi Win32_NetworkAdapterConfiguration |?{ $_.DefaultIPGateway -ne $null}).Index
    25 [array]$ip = (gwmi Win32_NetworkAdapterConfiguration -filter "index = $index").IPAddress
    26 $ConnectionID = (gwmi win32_networkadapter -filter "index = $index").NetConnectionID 
    27 #根据IP属于IDC设置DNS
    28 $ip2 = $ip[0].split(".")[0,1] -join "."
    29 If ($ip2 -eq "10.4")
    30     {
    31      $dnsservers="10.4.2.220","10.5.2.220","192.168.251.210"
    32      dnsconfig $ConnectionID  $dnsservers
    33     }
    34 Elseif ($ip2 -eq "10.5")  
    35     {
    36      $dnsservers="10.5.2.220","192.168.251.210","10.4.2.220"
    37      dnsconfig $ConnectionID  $dnsservers
    38     }
    39 Else 
    40    {
    41     $dnsservers="192.168.251.210","10.4.2.220","10.5.2.220"
    42     dnsconfig $ConnectionID  $dnsservers
    43    }
    44 
    45 #查看本地DNS服务器列表
    46 $dnss=gwmi win32_networkadapter -filter "NetConnectionStatus = 2"|foreach {(gwmi Win32_NetworkAdapterConfiguration -filter "index = $($_.index)").DNSServerSearchOrder}
    47 $dnss
  • 相关阅读:
    软件测试之接口
    软件测试之APP测试流程及策略
    软件测试之bug类型分类及缺陷管理
    软件测试之测试计划
    软件测试之web流程
    软件测试之生命周期模型
    软件测试之测试用例编写及编写规范
    软件测试之黑盒测试策略
    软件测试之基础知识
    PHP与AJAX
  • 原文地址:https://www.cnblogs.com/dreamer-fish/p/4042712.html
Copyright © 2020-2023  润新知