forked from noahdavids/packet-analysis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck-subnet.sh.html
126 lines (109 loc) · 3.97 KB
/
check-subnet.sh.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=windows-1252" />
<title>check-subnet.sh Information</title>
</head>
<body background="concret.jpg">
<center>
<h1>check-subnet.sh Information</h1>
<img src="bluebar.gif" width="576" height="14" alt="Blue Bar separator">
</center>
<p>
This macro compares a target IPv4 address with a subnet of the form X.X.X.X/NN and prints out TRUE if the target in in the subnet and FALSE if it is not. Its simple to do for 1 or 2 addresses and 1 or 2 subnets but if you have many addresses or subnets you do not want to do it by eyeball. It relies on ipcalc to determine the address range of the subnet.
<p>
There appear to be two versions of ipcalc depending on the OS distribution. In one you can can request the network and broadcast addresses while in the other you get the Host minimum and maximum addresses.
<p>
Output has the format of:
<br>
        IP-Address Subnet HostMin=IP-Address HostMax=IP-Address [TRUE|FALSE]<br>
    or<br>
        IP-Address Subnet Network=IP-Address Broadcast=IP-Address [TRUE|FALSE]
<p>
<b><h3>Usage</h3></b>
check-subnet.sh IP-Address SUBNET
<br><br>
<b>IP-Address</b>
<br>
Standard IP address in dotted decimal format, i.e. A.B.C.D
<br><br>
<b>SUBNET</b>
<br>
Subnet address in dotted decimal format/prefix, i.e. A.B.C.D/NN
<br><br>
<b><h3>Examples</h3></b>
Example 1 - executed on Ubuntu 18.04.3 LTS, ipcalc version 0.41
<center>
<table border=5>
<tr><td align=left>
<pre>
$ ./check-subnet.sh 1.1.1.63 1.1.1.1/26
1.1.1.63 1.1.1.1/26 HostMin=1.1.1.1 HostMax=1.1.1.62 FALSE
$ ./check-subnet.sh 1.1.1.61 1.1.1.1/26
1.1.1.61 1.1.1.1/26 HostMin=1.1.1.1 HostMax=1.1.1.62 TRUE
</pre>
</td></tr>
</table>
Figure 1
</center>
<p>
Example 2 - executed on Red Hat Enterprise Linux 7.5, ipcalc part of the initscripts-9.49.41-1.el7 package
<center>
<table border=5>
<tr><td align=left>
<pre>
$ ./check-subnet.sh 1.1.1.63 1.1.1.1/26
1.1.1.63 1.1.1.1/26 Netowork=1.1.1.0 Broadcast=1.1.1.63 FALSE
$ ./check-subnet.sh 1.1.1.61 1.1.1.1/26
1.1.1.61 1.1.1.1/26 Netowork=1.1.1.0 Broadcast=1.1.1.63 TRUE
</pre>
</td></tr>
</table>
Figure 2
</center>
<p>
Example 3 - executed on Red Hat Enterprise Linux 8.0, ipcalc version ipcalc 0.2.4
<center>
<table border=5>
<tr><td align=left>
<pre>
$ ./check-subnet.sh 1.1.1.63 1.1.1.1/26
1.1.1.63 1.1.1.1/26 Netowork=1.1.1.0 Broadcast=1.1.1.63 FALSE
$ ./check-subnet.sh 1.1.1.61 1.1.1.1/26
1.1.1.61 1.1.1.1/26 Netowork=1.1.1.0 Broadcast=1.1.1.63 TRUE
</pre>
</td></tr>
</table>
Figure 3
</center>
<p>
Example 4 - executed on Fedora 28, ipcalc version 0.2.3
<center>
<table border=5>
<tr><td align=left>
<pre>
$ ./check_subnet.sh 1.1.1.63 1.1.1.1/26
1.1.1.63 1.1.1.1/26 Netowork=1.1.1.0 Broadcast=1.1.1.63 FALSE
$ ./check_subnet.sh 1.1.1.61 1.1.1.1/26
1.1.1.61 1.1.1.1/26 Netowork=1.1.1.0 Broadcast=1.1.1.63 TRUE
</pre>
</td></tr>
</table>
Figure 4
</center>
<p>
You can find this script at <a href="https://github.com/noahdavids/packet-analysis/blob/master/check-subnet.sh">check-subnet.sh</a>
<br /><br />
<h5><center>
<img src="bluebar.gif" width="576" height="14" alt="Blue Bar separator">
<br />
This page was last modified on 2019-12-01</h5>
</center>
<a href="mailto:[email protected]"><img src="mailbox.gif" width="32" height="32" alt="mailbox" align="left" hspace=3>
Send comments and suggestions
<br />
</a>
</body>
</html>