EzDevInfo.com

subnet interview questions

Top subnet frequently asked interview questions

Java library to check if IPv4 or IPv6 address is in a given subnet

What library can I use to check if an IP address is in a given subnet? I could find libraries like the Apache Commons SubnetUtils (SubnetUtils.SubnetInfo.isInRange) but many do not support IPv6 yet.


Source: (StackOverflow)

Restricting access via IP-ranges (PHP)

Basically, I aim to allow my user to specify an ip range for access to a test. So lets say these values are stored in my database:

from: 148.197.34.112

To: 148.197.34.255

Are there any functions of which I can use to convert these ip addresses into numbers for comparison?

So obviously if a user tries to load a page...if his IP is not within an ip range, re-direct them.

Thanks in advance :)


Source: (StackOverflow)

Advertisements

How to check if an IP address is within a particular subnet

I have a subnet in the format 10.132.0.0/20 and an IP address from the ASP.Net request object.

Is there a .NET framework function to check to see if the IP address is within the given subnet?

If not, how can it be done? Bit manipulation, I guess?


Source: (StackOverflow)

Given an IP address and subnetmask, how do I calculate the CIDR?

Ok I can't seem to figure this out: given the following:

IP address = 192.168.1.0
Subnetmask = 255.255.255.240

Using c#, how do I calculate the CIDR notation 192.168.1.0/28 ? Is there an easy way to achieve this? Am I missing something?

Thanks!


Source: (StackOverflow)

IP Subnet Notation

On a lab to regarding network topology using port scanners, I am instructed "to develop a network inventory and topology for the 123.218.44.0/24 subnet."

What does the notation 0/24 mean there? I had assumed it meant to consider the network range 123.218.44.0 to 123.218.44.24. When I use nmap against a range, using parameters in this format:

nmap -sS -O 123.218.44.0/24

nmap reports that it scanned 256 hosts, presumably 123.218.44.0 to 123.218.44.255. There is only one host between 0 and 24, but there are 4 hosts between 101 and 255. I assume that I am meant to find all 5 of those hosts, but I don't understand the notation so I'm not sure. Can anyone clarify for me?


Source: (StackOverflow)

Using SQL to determine cidr value of a subnet mask

I'd like to find a way to do a SQL query that will calculate the cidr (bit representation) of a subnet mask stored in the database. So for example, I've got either 255.255.255.0 or its decimal value (4294967040) stored in the database. I'd like to do a select and get back /24 representation via the query.

I've done things like the following to determine the last IP of a subnet so I'm hoping to do something similar to determine the cidr representation of a mask.

select concat(inet_ntoa(ip_addr),'-',
    inet_ntoa(ip_addr+(POWER(2,32)-ip_mask-1))) range 
from subnets 
order by ip_addr

Preferably this would be a SQL statement that would work under mysql, postgres, oracle etc.


Source: (StackOverflow)

Calculating range of IPs from subnet mask

Say, I have a subnet of 255.255.255.242 and I have a known IP within that subnet say 192.168.1.101.

Now the way I calculate the range of IPs is this:

In the subnet mask, find the first octet that is not a 255. In my example, its the 4th octet, and its 242. So take 256 and subtract 242, which gives us 14. So we now know that these networks, the 192.168.1.x networks, all have a range of 14. So just start listing them...

192.168.1.0
192.168.1.14
192.168.1.28
....42
....56
....70
....84
....98
....112

Here we can stop. My address, 192.168.1.101 falls into the .98 network. .98 encompasses all ip addresses from 192.168.1.98 to 192.168.1.111, because we know that 192.168.1.112 starts the next network.

I want to confirm, whether this is the right and the easiest process to do so.


Source: (StackOverflow)

How can I determine network and broadcast address from the IP address and subnet mask?

IP Address: 130.45.34.36

Mask: 255.255.240.0

Net ID/Subnet Address?

Broadcast Address?


Source: (StackOverflow)

Calculate broadcast address from ip and subnet mask

I want to calculate the broadcast address for:

IP:     192.168.3.1
Subnet: 255.255.255.0
=       192.168.3.255

in C.

I know the way (doing fancy bitwise OR's between the inversed IP and subnet), but my problem is I come from the green fields of MacOSX Cocoa programing.

I looked into the source of ipcal, but wasn't able to integrate it into my code base. There must be a simple ten lines of code somewhere on the internet, I just can't find it. Could someone point me to a short code example of how to do it in C?


Source: (StackOverflow)

Check if IP is in subnet

I have a table A with IP addresses (ipNumeric) stored as unsigned ints and a table B with subnets (subnetNumeric):

INET_NTOA(ipNumeric) = 192.168.0.1
INET_NTOA(subnetNumeric) = 192.168.0.0

I'd like to check if this IP is a member of a subnet.

The subnets are Class A, B and C.

Is this possible to do in reasonable time in MySQL on the fly or should the subnet ranges be precomputed?


Source: (StackOverflow)

Is there native .NET type for CIDR subnets?

It's simple enough to code up a class to store/validate something like 192.168.0.0/16, but I was curious if a native type for this already existed in .NET? I would imagine it would work a lot like IPAddress:

CIDR subnet = CIDR.Parse("192.168.0.0/16");

Basically it just needs to make sure you're working with an IPv4 or IPv6 address and then that the number of bits your specifying is valid for that type.


Source: (StackOverflow)

Given the IP and netmask, how can I calculate the network address using bash?

In a bash script I have an IP address like 192.168.1.15 and a netmask like 255.255.0.0. I now want to calculate the start address of this network, that means using the &-operator on both addresses. In the example, the result would be 192.168.0.0. Does someone have something like this ready? I'm looking for an elegant way to deal with ip addresses from bash


Source: (StackOverflow)

How to get subnet mask using .net?

I want to get client subnet mask using c#.

How can I get it?


Source: (StackOverflow)

Android subnet scan

In my application I need to scan the local subnet (192.168.1.*) to collect the list of MAC addresses of all connected devices.

I currently use the following strategy:

  1. start simultaneously 255 ping commands with Runtime.exec("ping -c 1 <addr>")
  2. use waitFor() on each of the returned process to collect the exit code
  3. close input streams of processes and destroy them
  4. read the /proc/net/arp file and parse the MAC addresses

In most cases, this works very well and provides a fast scan.

But on some devices (such as android 1.5, and sometimes on >=4.0), the execution gets stuck at process creation (after a few ones have been successfully started) and there's no way to kill the running thread.

Do you see anything I could try to solve this issue? Or any other strategy that would not take too long?


Source: (StackOverflow)

Proper way to scan a range of IP addresses

Given a range of IP addresses entered by a user (through various means), I want to identify which of these machines have software running that I can talk to.

Here's the basic process:

  1. Ping these addresses to find available machines

  2. Connect to a known socket on the available machines

  3. Send a message to the successfully established sockets

  4. Compare the response to the expected response

Steps 2-4 are straight forward for me. What is the best way to implement the first step in .NET?

I'm looking at the System.Net.NetworkInformation.Ping class. Should I ping multiple addresses simultaneously to speed up the process? If I ping one address at a time with a long timeout it could take forever. But with a small timeout, I may miss some machines that are available.

Sometimes pings appear to be failing even when I know that the address points to an active machine. Do I need to ping twice in the event of the request getting discarded?

To top it all off, when I scan large collections of addresses with the network cable unplugged, Ping throws a NullReferenceException in FreeUnmanagedResources(). !?

Any pointers on the best approach to scanning a range of IPs like this?


Source: (StackOverflow)