get subnet mask and gateway from IP address

2019-05-21 03:50发布

问题:

How can i calculate subnet mask and gateway from an IP address?

Suppose my IP address is 180.12.24.68

Then how can i calculate this IP's subnet mask and gateway?

回答1:

You cannot calculate your subnet mask or gateway from just an IP address.

You can calculate the range that a potential gateway could be in given an IP address and a netmask. But, the range is basically ((My LAN segment Size) - MyIP). Generally this will be around 253 IP addresses unless you're on a large network.

Given a gateway and a netmask you can calculate a range of potential IP addresses you can configure yourself to use - but if you're manually configuring then you have the chance of clobbering an existing IP address. (This is why DHCP is good)

Given a gateway and an IP address you can calculate enough of your netmask that you can get your traffic to be routed - but depending on the subnet configuration you may not be able to talk to other machines that are on the same LAN segment. An example of this would be if your gateway is 10.1.3.254 and you configure your netmask as 255.255.255.0. The gateway (and the LAN) could actually be masked as 255.255.254.0 (basically, 2 class Cs worth of addresses in a contiguous segment).. So, you'd be able to get to the internet, but you might not be able to talk with 'local machines'.

In summation these are the possible outcomes:

  • mask + gateway = guessable but non-definitive IP address
  • mask + ip = guessable but non-definitive range of IP addresses you might find a gateway
  • ip + gateway = guessable but potentially misconfigured netmask