• Register
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.
14.6k points

Please log in or register to answer this question.

1 Answer

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
asked Mar 19 PkGuy 25.9k points
0 votes
1 answer 15 views
15 views
Problem: Hello ... Can anyone tell me that what does /24 mean in ip??
asked Mar 24 Ifra 43.4k points
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?
asked Jun 13 Chi Omega 159k points
0 votes
1 answer 5 views
5 views
Problem: Find network address from ip and subnet mask.
asked Jul 9 akhi 106k points
0 votes
1 answer 11 views
11 views
Problem: What are my options for dealing with this issue? read-host cmdlet is used to
asked Apr 7 rakib1 51.5k points
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.
asked May 9 Ashok Dileep 21.5k points
0 votes
1 answer 15 views
15 views
Problem: Which protocol can be used to discover the mac address?
asked May 15 Junia Phoebe 83.8k points
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 ?
asked Mar 30 Raj Tyagi 16k points
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?
asked Apr 2 salim1 60.6k points
0 votes
1 answer 3 views
3 views
Problem : Command to show all ip addresses on network.
asked Jul 11 Isac Christiaan 96.6k points