Jump to content

Recommended Posts

Posted (edited)

Basically trying to use 2 WMI Classes in vbscript so that I can get the below information hopefully from one query

 

* MAC Address

* Vendor

* Link Speed ( as in current link speed not the maximum speed the NIC Can get or use )

* Active / Status ( As in connected, not connected, obtaining ip address etc )

* I.Pv4 Address

* Subnet Mask

* Default Gateway

* DNS Servers

* DHCP Servers

* MTU of current Interface

 

win32_NetworkAdapter allows you to get MAC Address, vendor, link status, link speed etc where as win32_NetworkAdapterConfiguration allows you to get ip address, subnet mask, default gateway, dhcp servers, dns servers and other info

 

Currently have a HTA using vbscript and WMI but can only seem to do one query at a time ie one query on win32_NetworkAdapter and one query on win32_NetworkAdapterConfiguration but due to using NetworkAdapter to enumerate only physical network adapters into a dropdown menu I need it to pull the info for each relevant Interface each time you select a different interface from the drop down menu.

@Steve21 and @Arthur or anyone else :)

 

Thanks

Edited by mac_shinobi
  • 2 weeks later...
Posted (edited)

Also having issue(s) with the IP Address , as far as on some adapters that do not have an ip address ( version 4 or 6 ) you get an error message stating that the subscript range is out or does not exist so presume this is to do or related to me trying to split the results as originally it was outputting both the ipv4 and 6 addresses together on one line with a comma ie x.x.x.x, Y.Y.Y.Y

 

Could do with help on how to get the IPv4 and the IPv6 addresses better ?

@Chaddy - Is trying to help me with the CSS / GUI and could do with him re-uploading his version again as never got a chance to download his tweaked copy.

 


Network Utility
<br />
    <!--<br />
    body{<br />
      background-color:Menu;<br />
      color:MenuText;<br />
      cursor:default;<br />
      }<br />
    --><br />
table {<br />
  -moz-border-radius: 6px; /* FF1+ */<br />
  -webkit-border-radius: 6px; /* Saf3-4 */<br />
  border-radius: 6px; /* Opera 10.5, IE9, Saf5, Chrome */<br />
  -moz-box-shadow: 0 0 6px #959595 inset;<br />
  -webkit-box-shadow: 0px 0px 6px #959595 inset; /* Saf3.0+, Chrome */<br />
  box-shadow: 0px 0px 6px #959595 inset; /* Opera 10.5, IE9 */<br />
  border-collapse:collapse;<br />
  border: 5px solid black;<br />
  color: #00769B;<br />
  font-size: 1.1em;<br />
  text-align: left;}<br />
 
     APPLICATIONNAME="Interface Info"
    SCROLL="yes"
    SINGLEINSTANCE="yes"
    WINDOWSTATE="normal"



<br />
Sub Window_Onload<br />
strComputer = "."<br />
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")<br />
Set colItems = objWMIService.ExecQuery("Select * from Win32_NetworkAdapter Where NOT PNPDeviceID LIKE 'ROOT\\%'") 'PhysicalAdapter ='true'") <br />
<br />
For Each objItem in colItems<br />
Set objOption = Document.createElement("OPTION")<br />
objOption.Text = objItem.Description<br />
objOption.Value = objItem.Description<br />
NIC.Add(objOption)<br />
Next<br />
NIC.Focus<br />
End Sub<br />
<br />
Sub Obtain<br />
On Error Resume Next<br />
Dim MAC, Manu, NetStatus, LinkSpeed<br />
Dim IPvx, PName<br />
Dim x<br />
set objOption = window.event.srcElement<br />
<br />
<br />
strComputer = "."<br />
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")<br />
Set colNA = objWMIService.ExecQuery("Select * from Win32_NetworkAdapter Where Description ='" + objOption(objOption.selectedIndex).Text + "'")<br />
<br />
For Each objItem in colNA<br />
MAC = objItem.MACAddress<br />
Manu = objItem.Manufacturer<br />
NetStatus = objItem.NetConnectionStatus<br />
PName = objItem.ProductName<br />
Next<br />
<br />
Select Case NetStatus<br />
Case "0":<br />
NetStatus = "Disconnected"<br />
Case "1":<br />
NetStatus = "Connecting..."<br />
Case "2":<br />
NetStatus = "Connected"<br />
Case "3":<br />
NetStatus = "Dis-connecting"<br />
Case "4":<br />
NetStatus = "Hardware not present"<br />
Case "5":<br />
NetStatus = "Interface or Hardware disabled"<br />
Case "6":<br />
NetStatus = "Hardware malfunction"<br />
Case "7":<br />
NetStatus = "Media disconnected"<br />
Case "8":<br />
NetStatus = "Authenticating"<br />
Case "9":<br />
NetStatus = "Authentication succeeded"<br />
Case "10":<br />
NetStatus =  "Authentication failed"<br />
Case "11":<br />
NetStatus = "Invalid address"<br />
Case "12":<br />
NetStatus = "Credentials required"<br />
End Select<br />
<br />
Set colNAC = objWMIService.ExecQuery("Select * from Win32_NetworkAdapterConfiguration Where MACAddress='" + MAC + "'")<br />
<br />
For Each objItm in colNAC<br />
    If IsArray(objItm.IPAddress) Then<br />
        If UBound(objItm.IPAddress) = 0 Then<br />
            strIP =  objItm.IPAddress(0)<br />
        Else<br />
            strIP =  Join(objItm.IPAddress, ",")<br />
        End If<br />
    End If<br />
Next<br />
<br />
IPvx = Split(strIP, ",")<br />
<br />
Set objWMI = GetObject("winmgmts://" & strComputer & "/root\WMI")<br />
Set colLinkSpeed = objWMI.ExecQuery("SELECT * FROM MSNdis_LinkSpeed Where InstanceName='" + objOption(objOption.selectedIndex).Text + "'") <br />
For Each objItem in colLinkSpeed<br />
    Speed = objItem.NdisLinkSpeed/(1000^2)*100 & " Mbps"<br />
Next<br />
<br />
Interface.innerhtml = "Hardware Address : " & MAC & "<p>" & "IPv4 Address : " & IPvx(0) & "<p>" & "IPv6 Address : " & IPvx(1) & "<p>" & "Link Speed : " & Speed & "<p>" & "Link Status : " & NetStatus & "<p>" & "Vendor : " & Manu & "<p>" & _<br />
"Product Name : " & PName<br />
<br />
End Sub<br />
<br />



Select a network interface for information:




Interface Information:

</pre><table id="whitePanel" width="450px" cellpadding="0" cellspacing="0" border="0">



</table><br><br><br><br><br><b

 

Chaddy did mention about the CSS to round the corners off only working in IE 9 or above, I have version 10 and the rounded corners still do not work, have mucked about with the css which I know is applying as I can change the colours and width of the borders which seem to apply fine but the border-radius and other things I am putting in the css are not applying as far as rounding the corners on the table

 

Updated CSS :

 

 
<br />
    <!--<br />
    body{<br />
      background-color:Menu;<br />
      color:MenuText;<br />
      cursor:default;<br />
      }<br />
    --><br />
table {<br />
-webkit-border-radius:36px;<br />
-moz-border-radius:36px;<br />
border:5px solid;<br />
border-radius:36px;<br />
border-style:solid;<br />
border-color:#ff0000 #0000ff;<br />
border-collapse:collapse;}<br />
 

 

See attached PNG Image

HTA Capture.PNG

Edited by mac_shinobi

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...