Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

subnet masks etc..........

Status
Not open for further replies.

vgersh99

Programmer
Jul 27, 2000
2,146
US
logic:
1. given a subnet address and a mask [192.9.111.0 and 255.255.255.224]
2. and an address [(a) 192.9.111.1 OR (b) 192.9.111.50]
3. determine if (a) belongs to a subnet specified in 1.
[whereas (b) does NOT]

Say if I have a file subnets.txt
#subnet | mask
192.9.111.0|255.255.255.224
192.9.111.0|255.255.255.192


(a) will be validated by the FIRST record/row
(b) will be validated by the SECOND record/row


Anyone have any leads/tips or snippets I could elaborate on?!
vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
Hope this gives you an idea, you have plenty of skill to
fill in the blanks..

function hpn(add, arr,x) {
gsub(/255\./,&quot;&quot;,add)
x = split(add,arr,&quot;.&quot;)
if (x == 2) {
start = (256 - arr[1])
return (start * 256 - 2)
} else if (x == 1) {
return (256 - arr[1] - 2)
}
return &quot;FAIL&quot;
}

Based on the last octet value of $1 + last octet of host address. Will it fit under the math returned by the function given $2?
If so you have a winner.

example:
nval = function($1)
hrng = function(host) + nval
if (hrng <= hpn($2)) {
print 1
} else {
print 0
}
etc...


HTH
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top