Jkeith247 Posted April 3, 2012 Share Posted April 3, 2012 (edited) Hello all, I think I may be having an "off" day today as my mind seems weaker than usual.... I have been searching for some time now, trying to find a way to pull the subnet associated with an IP address and store it in a variable. Also, I have more than one network adapter on my computer thus I have more than one IP address... Basically, what I am trying to do is perform the calculation to determine the proper broadcast address for a network and I need the IP and Subnet to do this... The IP is the easy part, the subnet not so easy... Does anyone have any suggestions? I dabled around a bit with Win32_NetworkAdapterConfiguration but this seemed to be rather troublesome just to get the subnet address.... Any help is greatly appreciated. Thanks!! Edited April 3, 2012 by Jkeith247 Link to comment Share on other sites More sharing options...
iamtheky Posted April 3, 2012 Share Posted April 3, 2012 (edited) Scriptomatic takes the troublesome out of it, imho. returns all IPs and their corresponding subnets. Commented lines, if uncommented, will ask for an IP and retrieve only the subnet for that IP (if none found then returned all). Seemed less efficient than just looking at the entire list, but you may find a use. expandcollapse popup;~ $IP = inputbox ("Which IP?" , "Which IP do you want the subnet for?") $wbemFlagReturnImmediately = 0x10 $wbemFlagForwardOnly = 0x20 $colItems = "" $strComputer = "localhost" $Output="" $FOutput="" $objWMIService = ObjGet("winmgmts:" & $strComputer & "rootCIMV2") $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration", "WQL", _ $wbemFlagReturnImmediately + $wbemFlagForwardOnly) If IsObj($colItems) then For $objItem In $colItems $strIPAddress = $objItem.IPAddress(0) If $strIPAddress <> "" Then $FOutput &= $strIPAddress & @CRLF $strIPSubnet = $objItem.IPSubnet(0) If $strIPSubnet <> "" Then $FOutput &= $strIPSubnet & @CRLF & @CRLF ;~ If $strIPAddress = $IP Then $Output &= $strIPSubnet Next Else Msgbox(0,"WMI Output","No WMI Objects Found for class: " & "Win32_NetworkAdapterConfiguration" ) Endif ;~ If $output <> "" Then ;~ msgbox (0, '' , $output) ;~ Else msgbox (0, '' , $Foutput) ;~ Endif Func WMIDateStringToDate($dtmDate) Return (StringMid($dtmDate, 5, 2) & "/" & _ StringMid($dtmDate, 7, 2) & "/" & StringLeft($dtmDate, 4) _ & " " & StringMid($dtmDate, 9, 2) & ":" & StringMid($dtmDate, 11, 2) & ":" & StringMid($dtmDate,13, 2)) EndFunc Edited April 3, 2012 by boththose Jkeith247 1 ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__) Link to comment Share on other sites More sharing options...
Jkeith247 Posted April 4, 2012 Author Share Posted April 4, 2012 This is awesome. Thank you very much. This is exactly what I was looking for. Scriptomatic huh? I am gonna have to take a look at that. Thanks again! Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now