Jump to content

Calculate IP Subnet


burners
 Share

Recommended Posts

I would like to do 3 different things, 1 would be to display the Network Bits of an entered subnet

i.e.

255.255.255.0 = 24 bit

Next would be to calculate the Subnet Mask from the Network Bits (opposite of above)

i.e.

24 bit = 255.255.255.0

Last would be to find the Network Address based on the IP Address & Subnet Mask, this is probably the hardest.

i.e.

192.168.1.5 / 255.255.255.0 = 192.168.1.0

192.168.1.99 / 255.255.255.248 = 192.168.1.96

192.168.1.75 / 255.192.0.0 = 192.128.0.0

I found this thread but couldn't get enough out of it to do exactly what I'd like to do

http://www.autoitscript.com/forum/index.php?showtopic=7248&st=0&p=113993&hl=subnet&fromsearch=1&#entry113993

Thanks

~~--Feel Free to Steal my Sigs --~~FLAT LOOK____________________________________ROUNDED LOOK

Link to comment
Share on other sites

It's a good beginner's problem; not too hard. StringSplit() the dotted decimal mask and do a loop to work with one part at a time.

Post what you tried if you get stuck and you'll find plenty of help.

:graduated:

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

  • 3 years later...

I apologies for posting to an old topic but this was the only post I found with a problem similar to the one I was trying to solve.  Anyhows,  this is the solution I found which seems to work well;

;Set our IP and Subnet

$IPAddr="10.0.14.97"
$Subnet="255.255.255.248"

;Split them into arrays

$arrIP=StringSplit($IPAddr,".")
$arrSN=StringSplit($Subnet,".")

;use a BitwiseAND to calculate the network

ConsoleWrite(BitAND($arrIP[1],$arrSN[1]) & "." & BitAND($arrIP[2],$arrSN[2]) & "." & BitAND($arrIP[3],$arrSN[3]) & "." & BitAND($arrIP[4],$arrSN[4])& @CRLF)

Hope this helps someone.

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...