zoukankan      html  css  js  c++  java
  • 配置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
  • 相关阅读:
    如何从维护视图(Maintenace view)中取数据-[VIEW_GET_DATA]
    如何使用ref->*,field-symbols创建内表
    预制发票MIR7抬头行项目检查BADi-MRM_HEADER_CHECK
    如何跳转屏幕到MIGO-[MIGO_DIALOG]
    网络编程聊天室------客户端接收
    网络编程聊天室------客户端发送
    网络编程聊天室------客户端
    网络编程聊天室---------服务器线程类
    网络编程聊天室----服务器端
    小明滚出---响应对象HttpServletResponse和请求对象HttpServletRequest实例
  • 原文地址:https://www.cnblogs.com/dreamer-fish/p/4042712.html
Copyright © 2011-2022 走看看