Is an IP address in a Range
Posted on 2016-07-22
I have a spreadsheet that contains a list of IP addresses. I want to work out whether or not the values in this list of IPs are in any of the IP address ranges that I have on another worksheet using VBA and I can't get it to work.
I have created some code that uses the CIDR range to identify the first and last IP addresses in the range. I am then running a further loop to check if my queried IP is between those two values and I can't get it to work.
Can anyone help?
e.g. queried IP address = 18.104.22.168
start IP address in range is 22.214.171.124 and end IP address in range is 126.96.36.199
I run an if command in a loop something like:-
dim targetIP as int
dim startipaddress as int
dim endipaddress as int
If targetIP >= startipaddress and targetIP <= endipaddress then
I have tried using int, variant and Long values and none seem to work.
What am I doing wrong?