How can I determine the nearest IP address from certain IP address - networking

I have 3 IP addresses.
source IP : IP1
target IP : IP2, IP3
How can I determine what target IP is the nearest one from source IP by C-code
I don't need to know exact locations of IP addresses.
Just want to know what target IP is the nearest.
Please give me some advices.
Thank you.

Your ip is in form
aaa.bbb.ccc.ddd - 4 components.
First you should process 1st component:
compare (source.aaaa - target1.aaaa) and (source.aaaa - target2.aaaa)
(by module, so diffs are always positive)
If both are equal, then proceed with next component.
If different - the one with smaller difference is the closest one.

Use traceroute?
$traceroute <IP ADDR>
Should return hop information and speed, assuming you have the IP Addresses themselves

Related

Calculating network address

I'm trying to calculate the network address but I'm not entirely sure if I've done it correctly. Let's say the IP is: 130.243.14.29 and the Sub-mask is: 255.255.254.0
After calculating I'm getting: 130.243.14.0, is this correct or is the last number wrong? Is the broadcasting address the same thing as network address?
IP is: 130.243.14.29 and the Sub-mask is: 255.255.254.0
U have 510 IPs are useable
Network adress is 130.243.14.0
First ip address is 130.243.14.1
Last ip address is 130.243.15.254
broadcasting address is 130.243.15.255

IPv4 Network ID & Host ID

[I did my research]
I read the IPv4 and Subnetting chapters in the CCNA prep material. Watched several youtube videos and read through several forums. However, I still have a small issue because different sources use certain terms interchangeably however I want to be certain and confirm my understanding to avoid confusion.
[The Question]
Q1
Is the network address the same as the node address the same as the network id ?
Q2
Is the host address the same as the host id?
for instance:
in this ip 184.19.39.34 is 184.19 the network address == the node address == the network id?
is 39.34 the host address == the host id?
Thanks alot guys !
Q1: Basically, yes. You should note though that there are different kinds of network addresses such as IP addresses, subnet addresses/prefixes, or MAC addresses. The exact meaning of each term depends on context.
Q2: If the IP address/mask is 184.19.39.34/16 then 184.19.0.0/16 is the subnet address. 39.34 is the host part of the IP address while 184.19 is the network part. The IP address is split into these parts as indicated by the CIDR value or the network mask (255.255.0.0 for /16).
Note that this split is only relevant for routing and on the last hop, so you don't need to know the mask value of a far IP address.
Answer Q1 :
yes, But on as desired of the Mac or virtual IP or a value for the IP
Answer Q2 :
Gluttony complement each other
You can find a detailed answer here :
[https://www.geeksforgeeks.org/ip-addressing-introduction-and-classful-addressing/][1]

CIDR /28 calculation confusion

I am trying to learn how to calculate IP addresses from CIDR block.
For example, 10.88.135.144/28 or
10.88.135.10010000/28
From what I understand, that means first 28 bits are associated with network address while the rest 4 bits are host addresses. That would result in following IP range:
10.88.135.10010000 - 10.88.135.10011111
The first IP should be 10.88.135.144 and last IP address should be 10.88.135.159
But according to cidr.xyz. The first IP should be 10.88.135.145 and the last one should be 10.88.135.158.
I really can't figure out why. Can anyone explain the reason for me? Thanks!
Generally, the first IP is the network identifier and cannot be assigned to any device.This is used by router or switch on the network.
The last one is the broadcasting IP and cannot be assigned to any device as this IP is used by router or switch on the network to broadcast information.
https://www.quora.com/In-IP-addresses-what-is-meant-by-network-ID-and-host-ID
https://supportforums.cisco.com/t5/wan-routing-and-switching/what-is-broadcast-address/td-p/2494445#messageBodySimpleDisplay_1

Classless addressing

Your router has the IP address of 216.83.11.65/27. You wish to connect
a new system on the network. Which of the following addresses would
you assign to the new system.
A: 216.83.11.45
B: 216.83.11.87
C: 216.83.11.95
D: 216.83.11.96
The answer is B, but I'm not sure why. Can I get a step by step breakdown?
Your host network can chose from all the bits in the IP address, that are not used to define the network.1
So when looking at the Network Configuration you have, your network has the following range (you can use a subnet calculator to get to these values):
216.83.11.65 - 216.83.11.94
This rules out A and D, because you will need a router to get there (since the IP addresses cannot be directly reached within the network).
Your network internal broadcast address will be 216.83.11.95. This rules out answer C, because a host cannot have the broadcast address of your network.
So, only answer B stands.
1 I know that this might not be understandable at all. Cannot do it better. In this case please refer to Wikipedia: Classless Inter-Domain Routing

How to identify Network ID from an IP address

i already have studied about the internet IP and all those stuff, but i'm still confused about how to identify network ID from an given IP address, for example, if i have given an IP address: 192.168.250.0/24, so what will be the network ID?
can you guys help me?? and explain the method?
Thank you in advance
You need to convert the IP address and mask to binary, then logically AND them, then convert back to decimal:
192.168.250.0 -----> 11000000.10101000.11111010.00000000
24 bit mask -------> 11111111.11111111.11111111.00000000
=================================== <--- Logical AND
Network address ---> 11000000.10101000.11111010.00000000 ---> 192.168.250.0
This answer on Network Engineering describes how to do all your IP operations.
It s simple, your IP address is 192.168.250.0/24 and you should know that IP address is in a fact 32 bits value of zeros and ones. So it s easy for human to say listen this first 24 bits are network ID (network part) and remaining 8 bits are host ID (host part), but machines need parameter that will use to determine what bits are in network and what bits are ih host part. That s why we have subnet mask, that map IP address in a way that binary ones "1" map bits that belongs to network part and binary zeros "0" map bits that belongs to host part.
So your IP address in binary form is
11000000.10101000.11111010.00000000 when we add subnet mask then you have
11111111.11111111.11111111.00000000 or 255.255.255.0 in decimal form
-------------------------------------
11000000.10101000.11111010. bits maped by binary ones (network part)
.00000000 bits maped by binary zeros (host part)
If you count number of ones in subnetmask you will see that there are 24 binary ones, and that s why we use other notations for presenting subnet mask, and that is by something we call network prefix or "/24".
When host want to send packets he first must determine network address, but how he do that? Every host have IP address and subnet mask let say
192.168.250.6 and subnetmask /24 == 255.255.255.0 or in binary
11000000.10101000.11111010.00000110
11111111.11111111.11111111.00000000
------------------------------------- network hosts use logical AND operation
11000000.10101000.11111010.00000000
(notice that network address is address that have binary zeros in host part of IP address. Logical AND use two values (0 or 1), results of this logical operation is "1" only when both values are "1" (or you can easily rememmber it has to be "1" AND "1" to get "1" as result :) ).
After this host examine destination IP let s say 192.168.10.6, and host use again same operation and if result show that network part is identical with his IP than thay communicate directly or if they have different networkID hosts use gateway since destination is at another network.

Resources