https://github.com/stephenlb/geo-ip
Generate a list of IP Addresses and Associated Geographical Information ( City, Country, Zip, Lat, Long )
https://github.com/stephenlb/geo-ip
Last synced: 3 months ago
JSON representation
Generate a list of IP Addresses and Associated Geographical Information ( City, Country, Zip, Lat, Long )
- Host: GitHub
- URL: https://github.com/stephenlb/geo-ip
- Owner: stephenlb
- Created: 2019-03-01T01:09:04.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2020-04-17T22:20:28.000Z (about 6 years ago)
- Last Synced: 2025-05-06T22:57:01.404Z (about 1 year ago)
- Language: Python
- Size: 31.4 MB
- Stars: 17
- Watchers: 1
- Forks: 6
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
# Geo IP Generator
Generates a JSON dump of IP Addresses and associated Geo information.
Note that the valid public IP Address range is
from `'1.0.0.0/8'` to `'191.0.0.0/8'` excluding the reserved
Private IP Address ranges shown lower down in this readme.
```shell
docker build -t geo-ip .
docker run -e IPRANGE='54.0.0.0/30' geo-ip ## a few IPs
docker run -e IPRANGE='54.0.0.0/26' geo-ip ## a few more IPs
docker run -e IPRANGE='54.0.0.0/16' geo-ip ## a lot more IPs
docker run -e IPRANGE='0.0.0.0/0' geo-ip ## ALL IPs ( slooooowwwwww )
docker run -e IPRANGE='0.0.0.0/0' geo-ip > geo-ip.json ## ALL IPs saved to JSON File
docker run geo-ip
```
A little faster option for scanning all valid public addresses.
Just run the included helper script to generate all known valid public IP addresses:
```shell
./generate-all-valid-public-ip-addresses.sh
```
The `generate-all-valid-public-ip-addresses.sh` script looks like this:
```shell
for i in $(seq 1 191); do \
docker run -e IPRANGE="$i.0.0.0/8" geo-ip; \
sleep 1; \
done
```
This prints less than *4,228,250,625* JSON lines to STDOUT.
Here is an example of one of the lines:
```json
{"city": "Palo Alto", "ip": "0.0.0.0", "longitude": -122.1274,
"continent": "North America", "continent_code": "NA",
"state": "California", "country": "United States", "latitude": 37.418,
"iso_code": "US", "state_code": "CA", "aso": "PubNub",
"asn": "11404", "zip_code": "94107"}
```
## Private and Reserved IP Range
We automatically exclude non-usable IP addresses
following the guide from the wikipedia article:
https://en.wikipedia.org/wiki/Reserved_IP_addresses
```python
## Private IP Addresses
private = iptools.IpRangeList(
'0.0.0.0/8', '10.0.0.0/8', '100.64.0.0/10', '127.0.0.0/8',
'169.254.0.0/16', '172.16.0.0/12', '192.0.0.0/24', '192.0.2.0/24',
'192.88.99.0/24', '192.168.0.0/16', '198.18.0.0/15', '198.51.100.0/24',
'203.0.113.0/24', '224.0.0.0/4', '240.0.0.0/4', '255.255.255.255/32'
)
```