1 vote
28 views

# Problem :

Which is used to identify the network portion and the host ID portion of an IP address?
I am trying calculate the network and host portion of an IP address.

1 vote

# Solution :

Have you tried following:

``````#!/bin/sh
GetNumericIP()
{
ipbin=0
for part in `echo \$1 | awk -F'.' '{print \$1 " " \$2 " " \$3 " " \$4}'`
do
ipbin=`expr \$ipbin \* 256`
ipbin=`expr \$ipbin + \$part`
done
echo "\$ipbin"
}
GetSrtingIP()
{
ipbin=\$1
count=0
while [ \$count -le 3 ]
do
rem=`expr \$ipbin % 256`
ipbin=`expr \$ipbin / 256`
if [ -z "\$ipstr" ]
then
ipstr=\$rem
else
ipstr=`echo \${rem}.\${ipstr}`
fi
count=`expr \$count + 1`
done
echo \$ipstr
}
mask=\$2
maskbin=`GetNumericIP \$mask`
ip=\$1
ipbin=`GetNumericIP \$ip`
networkid=\$(( \$maskbin & \$ipbin ))
networkid=`GetSrtingIP \$networkid`
echo "networkid = \$networkid"``````
24.5k points

## Related questions

0 votes
1 answer 11 views
11 views
Problem: Please help I am trying to find? A command to find all ip addresses on network
0 votes
1 answer 15 views
15 views
Problem: Hello ... Can anyone tell me that what does /24 mean in ip??
0 votes
1 answer 7 views
7 views
Problem: Give me an answer please : Which of the following is the last ip address that can be assigned to hosts on the 166?
0 votes
1 answer 5 views
5 views
Problem: Find network address from ip and subnet mask.
0 votes
1 answer 11 views
11 views
Problem: What are my options for dealing with this issue? read-host cmdlet is used to
0 votes
1 answer 37 views
37 views
Problem: Can anyone help me with this complication? >Warning: permanently added the rsa host key for ip address.
0 votes
1 answer 15 views
15 views
Problem: Which protocol can be used to discover the mac address?
1 vote
1 answer 7 views
7 views
Problem: What is my ip address and port number ? Are they same ? What is the difference between them ? Can somebody explain ?
0 votes
1 answer 9 views
9 views
Problem: I tried looking for answer on the internet. But I didn't get any helpful tips. Is it possible for me to get details about my issue?
0 votes
1 answer 3 views
3 views
Problem : Command to show all ip addresses on network.