0

I have an AWS DynamoDB table that stores IP ranges with a pool_address, a mask and an identifier (that is originally coming from excel/csv), eg.: pool_address is 100.150.200.0 mask is /22 identifier is myrange

I have about 250 of those.

Im trying to use Lambda to check if a given IP address is in any of the ranges and if yes, return the identifier. E.g.: IP 100.150.200.1 returns 'myrange' IP 100.150.201.1 returns 'myrange' IP 100.150.220.1 returns False IP 100.150.199.1 returns False

I know PostreSQL has some specific datatypes (INET, CIDR) that would makes this a lot easier, but is there any good way to get this doen with DynamoDB?

Martin Vegas
  • 127
  • 1
  • 13

1 Answers1

0

I found an answer myself: Since I'm using Python in the Lambda code, I could simply use ipAddress, as explained in this answer: How can I check if an ip is in a network in Python?

>>> import ipaddress
>>> ipaddress.ip_address('192.168.0.1') in ipaddress.ip_network('192.168.0.0/24')
True
Martin Vegas
  • 127
  • 1
  • 13