ip-address

Convert CIDR notation into IP range

青春壹個敷衍的年華 提交于 2020-08-22 15:06:31
问题 We are using the GeoLite2 database in order to implement an IP -> country lookup. For performance reasons, we want to import the CSV and convert it to our own format. The CSV is represented like this: 5.39.40.96/27,3017382,3017382,,0,0 5.39.40.128/28,3017382,3017382,,0,0 5.39.40.144/28,2635167,3017382,,0,0 5.39.40.160/27,3017382,3017382,,0,0 5.39.40.192/26,3017382,3017382,,0,0 5.39.41.0/25,3017382,3017382,,0,0 5.39.41.128/26,3017382,3017382,,0,0 5.39.41.192/26,2635167,3017382,,0,0 5.39.42.0

How to modify regular expression for ip:port?

半腔热情 提交于 2020-08-07 08:01:48
问题 I have regular expression like match = re.findall(r'[0-9]+(?:\.[0-9]+){3}', source) It works fine to take something like 192.168.1.1 from source string. How I can modify this regular expression for make it work with something like this: 192.168.1.1:80 Thank You for help. P.S. Sorry for my bad english. 回答1: This will match IP addresses with ports numbers. match = re.findall(r'[0-9]+(?:\.[0-9]+){3}:[0-9]+', source) If you want to make it flexible to match IP address without the ports and With