63 lines
2.3 KiB
Plaintext
63 lines
2.3 KiB
Plaintext
Option Explicit
|
|
On Error Resume Next
|
|
|
|
Dim strComputer, objWMIService, colConfigs, objConfig, colAdapters, objAdapter, strNombre, strIP, strSubnet, strTipo, strMascaraBits, i
|
|
|
|
strComputer = "."
|
|
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
|
|
|
|
' Consultamos las configuraciones que tienen IP habilitada
|
|
Set colConfigs = objWMIService.ExecQuery("Select * from Win32_NetworkAdapterConfiguration Where IPEnabled = True")
|
|
|
|
For Each objConfig In colConfigs
|
|
' 1. Obtener el Nombre de la Interfaz (NetConnectionID)
|
|
Set colAdapters = objWMIService.ExecQuery("Select * from Win32_NetworkAdapter Where DeviceID = " & objConfig.Index)
|
|
strNombre = "N/A"
|
|
For Each objAdapter In colAdapters
|
|
strNombre = objAdapter.NetConnectionID
|
|
Next
|
|
|
|
' 2. Procesar cada dirección IP del adaptador
|
|
If Not IsNull(objConfig.IPAddress) Then
|
|
For i = 0 To UBound(objConfig.IPAddress)
|
|
strIP = objConfig.IPAddress(i)
|
|
strSubnet = objConfig.IPSubnet(i)
|
|
|
|
' 3. Verificar si es IPv6 (buscando el símbolo ":")
|
|
If InStr(strIP, ":") > 0 Then
|
|
strTipo = "IPv6"
|
|
strMascaraBits = strSubnet ' En IPv6, WMI ya devuelve el prefijo (ej: 64)
|
|
Else
|
|
strTipo = "IPv4"
|
|
strMascaraBits = MascaraABits(strSubnet)
|
|
End If
|
|
|
|
' Salida de datos
|
|
WScript.Echo "Interfaz: " & strNombre
|
|
WScript.Echo "Tipo: " & strTipo
|
|
WScript.Echo "IP: " & strIP
|
|
WScript.Echo "Máscara: /" & strMascaraBits
|
|
WScript.Echo "------------------------------------------"
|
|
Next
|
|
End If
|
|
Next
|
|
|
|
' Función para convertir máscara decimal (255.255.255.0) a bits (24)
|
|
Function MascaraABits(strMask)
|
|
Dim arrOctetos, intBits, octeto
|
|
intBits = 0
|
|
arrOctetos = Split(strMask, ".")
|
|
For Each octeto In arrOctetos
|
|
Select Case Int(octeto)
|
|
Case 255: intBits = intBits + 8
|
|
Case 254: intBits = intBits + 7
|
|
Case 252: intBits = intBits + 6
|
|
Case 248: intBits = intBits + 5
|
|
Case 240: intBits = intBits + 4
|
|
Case 224: intBits = intBits + 3
|
|
Case 192: intBits = intBits + 2
|
|
Case 128: intBits = intBits + 1
|
|
End Select
|
|
Next
|
|
MascaraABits = intBits
|
|
End Function |