allSystemsGo Posted October 3, 2013 Share Posted October 3, 2013 DirCreate('c:\temp') RunWait (@ComSpec & " /c " & ' ipconfig | Find "Subnet" > c:\temp\subnetmask.txt',"",@SW_HIDE) $file=FileOpen("c:\temp\subnetmask.txt") $netmask=FileReadLine($file,1) FileClose($file) ConsoleWrite($netmask) Link to comment Share on other sites More sharing options...
allSystemsGo Posted October 3, 2013 Share Posted October 3, 2013 Oops, I guess I'm late to the party. Link to comment Share on other sites More sharing options...
Gianni Posted October 3, 2013 Author Share Posted October 3, 2013 (edited) thanks dragan, the dll setup sounds pretty complex i'm not able to follow that stuff, anyway it looks that that dll (once started) provides a lot of info about the net. what strikes me as odd is, that all that code is needed to get a single piece of information. Not exactly the easiest way to get the subnet mask, perhaps an stronger synthesis will be possible. anyway I like this dll because not only gives the subnet mask info, but also it provides a concentration of network related infos, ready to be pulled out when and if needed (the difficult will be to get them out ). thanks for all the other good solutions posted here.(and even simpler as >mrflibblehat's post #7 with wmi and >BrewManNH's post #16 ) Edited October 3, 2013 by PincoPanco Chimp small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt.... Link to comment Share on other sites More sharing options...
allSystemsGo Posted October 3, 2013 Share Posted October 3, 2013 Did you try the method I posted? That is about as simple as it gets. Link to comment Share on other sites More sharing options...
Gianni Posted October 3, 2013 Author Share Posted October 3, 2013 Did you try the method I posted? That is about as simple as it gets. Hi allSystemsGo I had a look at your script, yes, it is very simple, but can only work if your computer has only one network card.For example, if there is even a wifi card in addition to the network card, then there are two addresses subnet mask, but your script will continue to return only the first and the second, which might be different, is not considered (even if the command | Find "Subnet" filters them all). in addition, even if the computer has only one network card, this can be used to assign multiple IP addresses (IP aliasing) with different subnet mask for each IP, and even in this case, your script will return only the first subnet address.Your script is very simple (I'm afraid too simple), but it works only in those (rare) cases that there is only one IP address to handle.thanks for your post allSystemsGobye Chimp small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt.... Link to comment Share on other sites More sharing options...
sahsanu Posted October 3, 2013 Share Posted October 3, 2013 You have got a lot of solutions including the use of ipconfig but... here is one more #include <Constants.au3> Local $ipaddress=@IPAddress1, $output Local $ipconfig = Run(@ComSpec & " /c ipconfig /all", "", @SW_HIDE, $STDOUT_CHILD) While 1 $output &= StdoutRead($ipconfig) If @error Then ExitLoop WEnd $output=StringStripWS($output,8) $subnetmask=StringRegExpReplace($output,".*" & $ipaddress & ".+?SubnetMask.+?:(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}).*","$1") MsgBox(0,"","IP is " & $ipaddress & " and SubnetMask is " & $subnetmask) Cheers, sahsanu Link to comment Share on other sites More sharing options...
Gianni Posted October 3, 2013 Author Share Posted October 3, 2013 Hi sahsanu the script is nice, but the output not so much....... I'd give a look at the regexp pattern thanks Chimp small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt.... Link to comment Share on other sites More sharing options...
sahsanu Posted October 4, 2013 Share Posted October 4, 2013 Hi sahsanu the script is nice, but the output not so much....... It's working fine on my computer. I'll double check it tomorrow ;-) Link to comment Share on other sites More sharing options...
allSystemsGo Posted October 4, 2013 Share Posted October 4, 2013 Hi allSystemsGo I had a look at your script, yes, it is very simple, but can only work if your computer has only one network card.For example, if there is even a wifi card in addition to the network card, then there are two addresses subnet mask, but your script will continue to return only the first and the second, which might be different, is not considered (even if the command | Find "Subnet" filters them all). in addition, even if the computer has only one network card, this can be used to assign multiple IP addresses (IP aliasing) with different subnet mask for each IP, and even in this case, your script will return only the first subnet address.Your script is very simple (I'm afraid too simple), but it works only in those (rare) cases that there is only one IP address to handle.thanks for your post allSystemsGobye Adding the '/all' parameter to ipconfig should do it, I think. I do not have a laptop present to try it out. Should give you about the same results as @sahsanu's script, but just return the subnet mask. May need to change FileReadLine() to FileRead(). Link to comment Share on other sites More sharing options...
Gianni Posted October 6, 2013 Author Share Posted October 6, 2013 I found on the forum this?do=embed' frameborder='0' data-embedContent>?do=embed' frameborder='0' data-embedContent>> remarkable?do=embed' frameborder='0' data-embedContent>?do=embed' frameborder='0' data-embedContent>> ?do=embed' frameborder='0' data-embedContent>?do=embed' frameborder='0' data-embedContent>>UDF by Ascend4ntusing that UDF, is possible to easily get the subnet mask of any IP set on the local computer.for example with a simple script like this: #include "_NetworkStatistics.au3" ; get this from the following link: ; http://www.autoitscript.com/forum/topic/151920-network-interface-info-statistics-and-traffic/?p=1088781 MsgBox(0, "", "IP: " & @IPAddress1 & @TAB & " Subnet Mask: " & _GetMask(@IPAddress1), 5) Func _GetMask($ip) ; get infos on network (see _NetworkStatistics.au3 UDF for info) Local $_net = _Network_IPv4AddressTable() If Not @error Then For $i = 0 To UBound($_net) - 1 ; scans all returned IP If $_net[$i][1] = $ip Then ; if found my IP Return $_net[$i][2] ; Return the mask EndIf Next EndIf Return "error" EndFunc ;==>_GetMask hope it can be useful to other users (the _NetworkStatistics.au3 UDF is in the file "NetworkStatistics.zip" on> this Ascend4nt's post bye mrflibblehat 1 Chimp small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt.... 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