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 = 188.8.131.52
start IP address in range is 184.108.40.206 and end IP address in range is 220.127.116.11
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?