Link to home
Create AccountLog in
Avatar of ferrarista
ferrarista

asked on

Excel - function to find subnet match

Hi guys.

I have a worksheet with a list of subnets in a CIDR format, example 192.168.0.15/24.
On another worksheet I have a list of servers, along with their respective IP address, say 192.168.0.10.

What kind of formula would allow me to compare the value of each server's IP address and match it with the relevant subnet ?

Thanks for any help.
Avatar of Samuel K.
Samuel K.
Flag of Kenya image

Thought you could utilise two functions.

Created two worksheets. One with subnet list and other with the server list.

Functions one. To get a potion of sub string in a subset set. I used a helper column on the server list which even when you hide still works fine.

=IFERROR(LEFT(A2,LEN(A2)-FIND(".",A2)),)  -to help identify position of last dot in the subnet defined. Check excel for understanding. Let me know in case of any query

Function two. Used the Vlookup to utilise results of function one.

=VLOOKUP(C3&"*",SUBNETS!$A$1:$B$15,2,FALSE) -With sub string of a subnet got with the help column defined, we can easily use vlookup to get the exact Subnet name as per your definition.

I wont explain much on but i would like you to refer to the attached excel and rate accordingly.
sev_subnet.xlsx
Avatar of Shaun Vermaak
That won't work on anything other than a 24bit subnet mask. Have a look at the macro in this post for solution for all masks
https://www.experts-exchange.com/questions/28993108/Vlookup-nonexact-IP-address-match.html
Shaun, sorry to disagree with you. It works. Download the excel attached and test.
This functions created don't have any consideration on the mask but the strictly string structure of any class of IP.
Is IP 192.168.0.130 in 192.168.0.0/25?
And 172.3.2.100 is not in 172.3.2.1/28 and your sheet says it is.
That subnet is only 172.3.2.1 - 172.3.2.14
User generated image
That is a sample data on the excel sheet.
I m working on a basis of this question, which is excel worksheet.
Your network calculation of course is correct but we are asked for reference which I believe is as simple as the excel.
Then see the link I posted which is a simple Excel Macro that works out subnet masks correctly.
And if I may, your sheet included the sample data with a 28bit mask which prompted my post

See attached
TestIP.xlsm
ASKER CERTIFIED SOLUTION
Avatar of ferrarista
ferrarista

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer