네트워킹을 위한 WMI 작업은 연결 및 IP 또는 MAC 주소에 대한 정보를 관리하고 가져옵니다. 다른 예제는 https://www.microsoft.com/technetTechNet ScriptCenter를 참조하세요.
이 항목에 표시된 스크립트 예제는 로컬 컴퓨터에서만 데이터를 가져옵니다. 스크립트를 사용하여 원격 컴퓨터에서 데이터를 가져오는 방법에 대한 자세한 내용은 원격 컴퓨터 WMI에 연결하는참조하세요.
다음 절차에서는 스크립트를 실행하는 방법을 설명합니다.
스크립트 실행하려면
- 코드를 복사하고 .vbs 확장명(예: filename.vbs파일에 저장합니다. 텍스트 편집기가 파일에 .txt 확장자를 추가하지 않는지 확인합니다.
- 명령 프롬프트 창을 열고 파일을 저장한 디렉터리로 이동합니다.
- 명령 프롬프트에서 cscript filename.vbs 입력합니다.
- 이벤트 로그에 액세스할 수 없는 경우 관리자 권한 명령 프롬프트에서 실행 중인지 확인합니다. 보안 이벤트 로그와 같은 일부 이벤트 로그는 UAC(사용자 액세스 제어)로 보호될 수 있습니다.
메모
기본적으로 cscript는 명령 프롬프트 창에 스크립트의 출력을 표시합니다. WMI 스크립트는 많은 양의 출력을 생성할 수 있으므로 출력을 파일로 리디렉션할 수 있습니다. 명령 프롬프트에서 cscript filename.vbs > outfile.txt 입력하여 filename.vbs 스크립트의 출력을 outfile.txt리디렉션합니다.
다음 표에서는 로컬 컴퓨터에서 다양한 형식의 데이터를 가져오는 데 사용할 수 있는 스크립트 예제를 나열합니다.
| ... WMI를 사용하여 네트워크 연결을 사용하지 않도록 설정하시겠습니까? |
DHCP를 사용하는 경우 Win32_NetworkAdapterConfiguration 및 ReleaseDHCPLease 메서드를 사용하여 IP 주소를 해제합니다. DHCP를 사용하지 않는 경우 WMI를 사용하여 네트워크 연결을 사용하지 않도록 설정할 수 없습니다. 네트워크 연결을 다시 사용하도록 설정하려면 objNetCard.RenewDHCPLease사용합니다. 또한 ReleaseDHCPLeaseAll 및 RenewDHCPLeaseAll 메서드를 사용하여 모든 DHCP 임대를 해제하거나 갱신할 수 있습니다.
strComputer = "."
Set objWMIService = GetObject( _
"winmgmts:\\" & strComputer & "\root\cimv2")
Set colNetCards = objWMIService.ExecQuery _
("Select * From Win32_NetworkAdapterConfiguration " _
& "Where IPEnabled = True")
For Each objNetCard in colNetCards
objNetCard.ReleaseDHCPLease()
Next
|
$Computer = "."
$net = Get-WMIObject -class Win32_NetworkAdapterConfiguration -ComputerName $computer
$netenabled = $net | where {$_.IPenabled}
foreach ($NetCard in $netenabled) {
"Releasing lease on: {0}" -f $netcard.caption
$netcard.ReleaseDHCPLease()
}
|
|
| NIC를 비활성화하거나 활성화하시겠습니까? |
Win32_NetworkAdapter 클래스와 Disable 메서드 또는 Enable 메서드를 사용합니다. |
| ... 지정된 네트워크 연결에 할당된 IP 주소를 확인하시겠습니까? |
Win32_NetworkAdapter 클래스와 NetConnectionID 속성을 사용하여 네트워크 연결의 MAC 주소를 확인합니다. 그런 다음 Win32_NetworkAdapterConfiguration 클래스를 사용하여 MAC 주소와 연결된 IP 주소를 찾습니다.
strComputer = "." Set objWMIService = GetObject(_ "winmgmts:\\" & strComputer & "\root\cimv2") Set colItems = objWMIService.ExecQuery _ ("Select * From Win32_NetworkAdapter " _ & "Where NetConnectionID = " & _ "'Local Area Connection 2'") colItems strMACAddress = objItem.MACAddress Next의 각 objItem에 대해
Set colItems = objWMIService.ExecQuery _ ("Select * From Win32_NetworkAdapterConfiguration")
For Each objItem in colItems
If objItem.MACAddress = strMACAddress Then
For Each strIPAddress in objItem.IPAddress
Wscript.Echo "IP Address: " & strIPAddress
Next
End If
Next
|
strComputer = "."
Set objWMIService = GetObject( _
"winmgmts:\\" & strComputer & "\root\cimv2")
Set colNics = objWMIService.ExecQuery _
("Select * From Win32_NetworkAdapter " _
& "Where NetConnectionID = " & _
"'Local Area Connection'")
For Each objNic in colNics
Set colNicConfigs = objWMIService.ExecQuery _
("ASSOCIATORS OF " _
& "{Win32_NetworkAdapter.DeviceID='" & _
objNic.DeviceID & "'}" & _
" WHERE AssocClass=Win32_NetworkAdapterSetting")
For Each objNicConfig In colNicConfigs
For Each strIPAddress in objNicConfig.IPAddress
Wscript.Echo "IP Address: " & strIPAddress
Next
Next
Next
|
|
| ... 네트워크 어댑터의 MAC 주소를 확인하시겠습니까? |
Win32_NetworkAdapterConfiguration 클래스를 사용하고 MACAddress 속성의 값을 확인합니다. |
| ... 컴퓨터의 IP 주소를 확인하시겠습니까? |
Win32_NetworkAdapterConfiguration 클래스를 사용하고 IPAddress 속성의 값을 확인합니다. 이 값은 배열로 반환되므로 For-Each 루프를 사용하여 값을 가져옵니다.
strComputer = "."
Set objWMIService = GetObject( _
"winmgmts:\\" & strComputer & "\root\cimv2")
Set IPConfigSet = objWMIService.ExecQuery _
("Select IPAddress from Win32_NetworkAdapterConfiguration ")
For Each IPConfig in IPConfigSet
If Not IsNull(IPConfig.IPAddress) Then
For i=LBound(IPConfig.IPAddress) _
to UBound(IPConfig.IPAddress)
WScript.Echo IPConfig.IPAddress(i)
Next
End If
Next
|
$Computer = "."
$IPconfigset = Get-WmiObject Win32_NetworkAdapterConfiguration
# Iterate and get IP address
$count = 0
foreach ($IPConfig in $IPConfigSet) {
if ($Ipconfig.IPaddress) {
foreach ($addr in $Ipconfig.Ipaddress) {
"IP Address : {0}" -f $addr;
$count++
}
}
}
if ($count -eq 0) {"No IP addresses found"}
else {"$Count IP addresses found on this system"}
|
|
| ... DHCP를 통해 IP 주소 가져오기를 시작하도록 컴퓨터를 구성하시겠습니까? |
Win32_NetworkAdapterConfiguration 클래스와 EnableDHCP 메서드를 사용합니다.
strComputer = "."
Set objWMIService = GetObject(_
"winmgmts:\\" & strComputer & "\root\cimv2")
Set colNetAdapters = objWMIService.ExecQuery _
("Select * from Win32_NetworkAdapterConfiguration " _
& "where IPEnabled=TRUE")
For Each objNetAdapter In colNetAdapters
errEnable = objNetAdapter.EnableDHCP()
Next
|
|
| ... 컴퓨터에 고정 IP 주소를 할당하시겠습니까? |
Win32_NetworkAdapterConfiguration 클래스 및 EnableStatic 메서드를 사용합니다.
strComputer = "."
Set objWMIService = GetObject( _
"winmgmts:\\" & strComputer & "\root\cimv2")
Set colNetAdapters = objWMIService.ExecQuery _
("Select * from Win32_NetworkAdapterConfiguration " _
& "where IPEnabled=TRUE")
strIPAddress = Array("192.168.1.141")
strSubnetMask = Array("255.255.255.0")
strGateway = Array("192.168.1.100")
strGatewayMetric = Array(1)
For Each objNetAdapter in colNetAdapters
errEnable = objNetAdapter.EnableStatic( _
strIPAddress, strSubnetMask)
errGateways = objNetAdapter.SetGateways(_
strGateway, strGatewaymetric)
Next
|
|
| ... RAS 및 VPN 연결과 같은 항목에 대한 정보를 검색하지 않고 네트워크 어댑터에 대한 정보를 얻을 수 있나요? |
Win32_NetworkAdapterConfiguration 클래스를 사용합니다.
WQL 쿼리에서 이 절을 사용하십시오: IPEnabled = True.
strComputer = "."
Set objWMIService = GetObject( _
"winmgmts:\\" & strComputer & "\root\cimv2")
Set IPConfigSet = objWMIService.ExecQuery _
("Select IPAddress from Win32_NetworkAdapterConfiguration" _
& " where IPEnabled=TRUE")
For Each IPConfig in IPConfigSet
If Not IsNull(IPConfig.IPAddress) Then
For i=LBound(IPConfig.IPAddress) _
to UBound(IPConfig.IPAddress)
WScript.Echo IPConfig.IPAddress(i)
Next
End If
Next
|
|
| Ping.exe을 사용하지 않고 컴퓨터를 ping 하려면 어떻게 해야 하나요? |
Win32_PingStatus 클래스를 사용합니다.
Win32_PingStatus IPv4 주소와 IPv6 주소가 모두 있는 컴퓨터에 대한 데이터를 반환할 수 있습니다.
strComputer = "." Set objWMIService = GetObject(_ "winmgmts:\\" & strComputer & "\root\cimv2") set colPings = objWMIService.ExecQuery _ ("Select * from Win32_PingStatus where Address = '192.168.1.1.1'") For Each objStatus in colPings
If IsNull(objStatus.StatusCode) _
or objStatus.StatusCode<>0 Then
WScript.Echo "Computer did not respond."
Else
Wscript.Echo "Computer responded."
End If
Next
|
strComputer = "client1"
Set objShell = CreateObject("WScript.Shell")
Set objScriptExec = objShell.Exec( _
"ping -n 2 -w 1000 " & strComputer)
strPingResults = LCase(objScriptExec.StdOut.ReadAll)
If InStr(strPingResults, "reply from") Then
If InStr(strPingResults, "destination net unreachable") Then
WScript.Echo strComputer & "did not respond to ping."
Else
WScript.Echo strComputer & " responded to ping."
End If
Else
WScript.Echo strComputer & " did not respond to ping."
End If
|
|
-
스크립트 및 애플리케이션 대한 WMI 작업
-
WMI C++ 애플리케이션 예제
-
TechNet ScriptCenter