Ip Subnet Mask, network Devision - networking

I' ve been trying all day to find out how to devide a network into 4 networks:
I got the IP: 195.232.176.0 /20
So by converting the IP into the following formation
[octal 1] . [octal 2] . [octal 3] . [octal 4]
11000011 . 11101000 . 10110000 . 00000000
By setting 1 in the first 20bits starting counting from the left I have:
==================20bits==============
11111111 . 11111111 . 1111 0000 . 00000000 = 225.225.240.0 (Subnet Mask)
So the four networks are :
Starting IP Address: 195.232.176.0 /20
195.232.x.0 /20
195.232.x.0 /20
195.232.x.0 /20
195.232.x.0 /20
Are the 4 networks correct?? My problem is on how will I put the x numbers with the data I have found!

It's easy peasy once you know subnetting.
Let's have a closer look at the IP 195.232.176.0 /20. What is the full range?
195.232.176.0 to 195.232.191.255
So to divide the 195.232.176.0 /20 up into 4 subnets, you'll need a /22 mask for each subnet.
195.232.176.0/22 (195.232.176.0 to 195.232.179.255)
195.232.180.0/22 (195.232.180.0 to 195.232.183.255)
195.232.184.0/22 (195.232.184.0 to 195.232.187.255)
195.232.188.0/22 (195.232.188.0 to 195.232.191.255)

Related

python-textFSM parse multiple line

i have to parse an isis database and i have pb to capture some metrics.
My templates is :
Value Required LSPID (.*\.\d+\-00)
Value OVERLOAD_BIT ([0,1])
Value HOSTNAME (.*)
Value IPADD (\d+\.\d+\.\d+\.\d+)
Value List CONNECTED_METRIC (\d+)
Value List LSPID_PEER (.*)
Value List SUBNET_METRIC (\d+)
Value List SUBNET (\d+\.\d+\.\d+\.\d+\/\d+)
Start
^${LSPID}.*[0,1]/[0,1]/${OVERLOAD_BIT}
^\s+Hostname:\s+${HOSTNAME}
^\s+IP\s+Address:\s+${IPADD} -> Metrics
Metrics
^\s+Metric:\s+${CONNECTED_METRIC}\s+IS-Extended\s+${LSPID_PEER}
^\s+Metric:\s+${SUBNET_METRIC}\s+IP\s+${SUBNET} -> Record Start
My datas to parse are :
ROUTER_A.00-00 0x00020850 0xE97D 1122 0/0/0
Area Address: 49.0001
NLPID: 0xCC
Hostname: ROUTER_A
IP Address: 172.17.32.2
Metric: 1000 IS-Extended ROUTER_D.00
Metric: 100 IS-Extended ROUTER_E.00
Metric: 100 IS-Extended ROUTER_F.00
Metric: 1 IP 172.17.32.2/32
Metric: 1 IP 172.25.9.142/32
ROUTER_B.00-00 0x00064747 0x27E9 1183 0/0/0
Area Address: 49
NLPID: 0xCC
Hostname: ROUTER_B
Metric: 1000000 IS-Extended ROUTER_G.00
Metric: 1000000 IS-Extended ROUTER_H.00
IP Address: 192.168.12.51
Metric: 0 IP 172.25.92.155/32
Metric: 0 IP 192.168.12.51/32
ROUTER_C.00-00 0x0006B0C0 0x4632 1113 0/0/1
Area Address: 49.0001
NLPID: 0xCC
Hostname: ROUTER_C
Router ID: 192.168.128.131
IP Address: 172.25.92.62
Metric: 10000 IS-Extended ROUTER_I.00
Metric: 50000 IS-Extended ROUTER_J.00
Metric: 1 IP 172.25.92.62/32
Metric: 1 IP 192.168.128.131/32
ROUTER_K.00-00 0x00020850 0xE97D 1122 0/0/0
Area Address: 49.0001
NLPID: 0xCC
Hostname: ROUTER_K
IP Address: 172.17.72.2
Metric: 1000 IS-Extended ROUTER_D.00
Metric: 100 IS-Extended ROUTER_E.00
Metric: 100 IS-Extended ROUTER_F.00
And i have this result :
['ROUTER_A.00-00', '0', 'ROUTER_A', '172.17.32.2', ['1000', '100', '100'], ['ROUTER_D.00', 'ROUTER_E.00', 'ROUTER_F.00'], ['1'], ['172.17.32.2/32']]
['ROUTER_B.00-00', '0', 'ROUTER_B', '192.168.12.51', ['1000000', '1000000'], ['ROUTER_G.00', 'ROUTER_H.00'], ['0'], ['172.25.92.155/32']]
['ROUTER_C.00-00', '1', 'ROUTER_C', '172.25.92.62', ['10000', '50000'], ['ROUTER_I.00', 'ROUTER_J.00'], ['1'], ['172.25.92.62/32']]
['ROUTER_K.00-00', '0', 'ROUTER_K', '172.17.72.2', ['1000', '100', '100'], ['ROUTER_D.00', 'ROUTER_E.00', 'ROUTER_F.00'], [], []]
We can see that only the first "ip metric" are parsed (no parse for ip address 172.25.9.142/32 by example).
Could you help me to find what is wrong ?
I made a workaround :
i have edited the data file and inserted a tag that i match in fsm template.
So now i have this template and it's working fine but if someone has the solution to avoid to edit the source file it will be smarter than this workaround:
Value Required LSPID (.*\.\d+\-00)
Value OVERLOAD_BIT ([0,1])
Value HOSTNAME (.*)
Value IPADD (\d+\.\d+\.\d+\.\d+)
Value List CONNECTED_METRIC (\d+)
Value List LSPID_PEER (.*)
Value List SUBNET_METRIC (\d+)
Value List SUBNET (\d+\.\d+\.\d+\.\d+\/\d+)
Value END_LSPID (END_LSPID)
Start
^${LSPID}.*[0,1]/[0,1]/${OVERLOAD_BIT}
^\s+Hostname:\s+${HOSTNAME}
^\s+IP\s+Address:\s+${IPADD} -> Metrics
Metrics
^\s+Metric:\s+${CONNECTED_METRIC}\s+IS-Extended\s+${LSPID_PEER}
^\s+Metric:\s+${SUBNET_METRIC}\s+IP\s+${SUBNET}
^${END_LSPID} -> Record Start

Subnetwork and Subnet Mask

Block - 130.0.0.0/25 .
Want to create 8 subnet.
Binary Form of Block will be
1000 0010.0000 0000.0000 0000.0000 0000/25
Subnet mask would be
1111 1111.1111 1111.1111 1111.1000 0000
How will I make 8 subnetwork out of this?
You can handle 2 ^ 7 = 128 IP's (binary form: 000 0000 - 111 1111). Each subnetwork will have 128 / 8 = 16 IP's. So the subnetworks will look as follows.
130.0.0.0 - 130.0.0.15
130.0.0.16 - 130.0.0.31
130.0.0.32 - 130.0.0.47
130.0.0.48 - 130.0.0.63
130.0.0.64 - 130.0.0.79
130.0.0.80 - 130.0.0.95
130.0.0.96 - 130.0.0.111
130.0.0.112 - 130.0.0.127

While subnetting Class B address how to find out subnets number?

In this question why we subtract 2 from 2^3 while calculating number of subnets. While in CCNA books 2 is not subtracted?
172.16.0.0 /19
Subnets 2^3 -2 = 6
Hosts 2^13 -2 = 8190
Block Size 256-224 = 32
When you want to Subnet the Class B 172.16.0.0 to a / 19 subnet, you add 3 bits to the default Class B netmask (which is /16)
The number of subnet available is 2^3 = 8 Subnets.
Concerning the number of Hosts you can have per subnet, it is 2^13-2
The number 13 comes from 32 (number of bit in a netmask) - (number of bits affected to the MASK part 19)
You substract 2 for each subnet because the first host and the last host are reserved for Network and Broadcast address.
If i don't answer your question, please give more information about what you need.
This is for your subnet mask
Address: 172.16.0.0 10101100.00010000.000 00000.00000000
Netmask: 255.255.224.0 = 19 11111111.11111111.111 00000.00000000
Wildcard: 0.0.31.255 00000000.00000000.000 11111.11111111
=>
Network: 172.16.0.0/19 10101100.00010000.000 00000.00000000 (Class B)
Broadcast: 172.16.31.255 10101100.00010000.000 11111.11111111
HostMin: 172.16.0.1 10101100.00010000.000 00000.00000001
HostMax: 172.16.31.254 10101100.00010000.000 11111.11111110
Hosts/Net: 8190 (Private Internet)

calculating subnet mask?

how can i calculate the subnet mask having ip address 128.2.19.4 and belong to the subnet 128.2.19.0/25.please give me the detail procedure.i want to learn to calculate.
Here's the algorithm with your example:
The subnet mask is just a representation of the "/25" part of your subnet address.
In IPv4, addresses are 32 bits long, the first 25 bits of which are ones:
1111 1111 1111 1111 1111 1111 1000 0000
addresses are given in octets -- 8 bits each:
octet 1 . octet 2 . octet 3 . octet 4
0000 0000 0000 0000 0000 0000 0000 0000
1111 1111 1111 1111 1111 1111 1000 0000
So a decimal representation of each octet is:
255 . 255 . 255 . 128
That means that your subnet mask would be:
255.255.255.128
The subnet mask is a bitmask. 25 means that 25 out of 32 bits (starting from the top) is used for the network, and the rest for the hosts.
In bytes: 128.2.19.0
In binary 10000000 00000010 00010011 00000000
The bitmask: 11111111 11111111 11111111 10000000
Ergo: ------- network ------------ host
The last 7 bits are used for hosts. The bitmask as bytes is 255.255.255.128.
Here's how you can do it in C:
#include <stdio.h>
#include <arpa/inet.h>
uint32_t cidr_to_netmask(uint8_t cidr)
{
uint8_t unset_bits = 32 - cidr;
return ntohl(0xffffffff << unset_bits);
}
int main(void)
{
uint8_t cidr = 25;
uint32_t _netmask = cidr_to_netmask(cidr);
struct in_addr _netmask_addr = { _netmask };
char netmask[16];
if (inet_ntop(AF_INET, (struct in_addr *)&_netmask_addr, (char *)&netmask, sizeof(netmask)) == NULL) {
fprintf(stderr, "error.\n");
return 1;
}
printf("%d = %s\n", cidr, netmask);
return 0;
}
Output:
25 = 255.255.255.128

Need some help interpreting tcpdump output

I've checked the tcpdump man page and thought I understood the example provided there. But the one that I am getting is something I'm not able to understand completely.
ORIGINAL: Simulator Output
LINE 1: 20:01:13.442111 IP 10.0.0.1.12345 > 10.0.0.2.54321: S 1234:1234(0) win 65535
LINE 2: 20:01:13.471705 IP 10.0.0.2.54321 > 10.0.0.1.12345: S 4321:4321(0) ack 1235 win 65535
LINE 3: 20:01:13.497389 IP 10.0.0.1.14640 > 10.0.0.2.12756: . ack 4322 win 65535
LINE 4: 20:01:13.497422 IP 10.0.0.1.12345 > 10.0.0.2.54321: . 1235:2682(1447) win 65535
LINE 5: 20:01:14.023273 IP 10.0.0.2.12756 > 10.0.0.1.14640: . ack 5768 win 65535
This is what I understand:
LINE 1: 1 sends 2 0 bytes starting with SEQ number 1234
LINE 2: 2 sends 1 0 bytes starting with SEQ number 4321 and an ACK = (1's SEQ + 1) i.e. 1235
LINE 3: 1 sends 2 0 bytes with an ACK = (2's SEQ + 1) i.e. 4322
LINE 4: 1 sends 2 1447 bytes starting with SEQ number 1235 until 2682 (1447 bytes in total)
LINE 5: 2 sends 1 0 bytes with an ACK = 5768? What is this number? Isn't it supposed to be 2683?
Maybe I am missing something too obvious. Can someone point it out please?
EDIT 1: Simulator output (grepped one connection info)
20:01:13.442111 IP 10.0.0.1.12345 > 10.0.0.2.54321: S 1234:1234(0) win 65535
20:01:13.471705 IP 10.0.0.2.54321 > 10.0.0.1.12345: S 4321:4321(0) ack 1235 win 65535
20:01:13.497422 IP 10.0.0.1.12345 > 10.0.0.2.54321: . 1235:2682(1447) win 65535
20:01:14.573322 IP 10.0.0.2.54321 > 10.0.0.1.12345: . ack 5981 win 65535
20:01:14.593870 IP 10.0.0.1.12345 > 10.0.0.2.54321: . 4129:5576(1447) win 65535
20:01:14.639457 IP 10.0.0.1.12345 > 10.0.0.2.54321: . 7023:8470(1447) win 65535
20:01:14.639606 IP 10.0.0.1.12345 > 10.0.0.2.54321: . 9917:10640(723) win 65535
20:01:14.660971 IP 10.0.0.2.54321 > 10.0.0.1.12345: . ack 11769 win 65535
20:01:14.693847 IP 10.0.0.1.12345 > 10.0.0.2.54321: . 12087:13534(1447) win 65535
20:01:14.726564 IP 10.0.0.2.54321 > 10.0.0.1.12345: . ack 15964 win 65535
Question: The ACK still seems to be different. It is 5981 instead of 2683.
EDIT 2: Real TCP output
22:20:14.492625 IP 72.14.204.99.80 > 10.0.2.15.59745: S 255616001:255616001(0) ack 1727704513 win 65535 <mss 1460>
22:20:14.495606 IP 10.0.2.15.59745 > 72.14.204.99.80: . ack 255616002 win 5840
22:20:14.501015 IP 10.0.2.15.59745 > 72.14.204.99.80: P 1727704513:1727705327(814) ack 255616002 win 5840
22:20:14.501746 IP 72.14.204.99.80 > 10.0.2.15.59745: . ack 1727705327 win 65535
22:20:14.562197 IP 72.14.204.99.80 > 10.0.2.15.59745: P 255616002:255616102(100) ack 1727705327 win 65535
22:20:14.562298 IP 10.0.2.15.59745 > 72.14.204.99.80: . ack 255616102 win 5840
22:20:14.630749 IP 10.0.2.15.59745 > 72.14.204.99.80: P 1727705327:1727706096(769) ack 255616102 win 5840
22:20:14.631228 IP 72.14.204.99.80 > 10.0.2.15.59745: . ack 1727706096 win 65535
22:20:14.692324 IP 72.14.204.99.80 > 10.0.2.15.59745: P 255616102:255616338(236) ack 1727706096 win 65535
22:20:14.692361 IP 10.0.2.15.59745 > 72.14.204.99.80: . ack 255616338 win 6432
Question: I tried as per your suggestion and grep'ed one connection's output. But this time, why is the ACK the way it is instead of SEQ+1?
check from the port number, It seems that LINE1, LINE2 and LINE5 belong to one session while LINE2 and LINE4 is in another session.
Instead using tcpdump for packet analysis, I highly suggest you to capture packets with tcpdump, and analyze the result with wireshark tool.
EDIT:
For the simulator stream, it mess up. Since the 10.0.0.1 -> 10.0.0.2's packets's sequence numbers is not completely, so I think maybe there some packet did not be captured and the timing is not show the real status. so you can ignore it.
For the real stream, it is okay. For syn packet, ack reply = seq +1; for content sending, ack = seq + len. The stream actually show this to us.

Resources