Jump to content

how to easily get the subnet mask?


 Share

Go to solution Solved by dragan,

Recommended Posts

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 by PincoPanco

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Link to comment
Share on other sites

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 allSystemsGo

bye

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Link to comment
Share on other sites

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

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 allSystemsGo

bye

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

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 Ascend4nt
using 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

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Link to comment
Share on other sites

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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...