This project use scapy to do the traceroute and ipgeolocation.ip to geolocate the ips. The command will store the traceroutes in a file and in a sqlite database.
Install miniconda link
Download the geolite2 database link
Create an account in ipgeolocation.ip, copy the apiKey and replace it in the file .env
$ conda create -n traces python=3.6
$ conda activate traces
$ conda install scapy cartopy
$ pip install geoip2 dataclasses python-dotenv
$ pip install dash
$ pip install pandas
$ conda activate traces
This command will create test.db case exist will overwrite it.
$ python database.py
The following command will create a file like this 42bc99cb-8387-4918-ab49-5ab574a2b7ab
$ sudo python tracer.py www.example.com
The traceroute hops will be store in the traces.sqlite database the id of the trace is the same as the file above.
create map takes two params first is the geomaplite.mmdb pathfile sencod is the file created by tracer.py
$ python trace_map.py /path/to/geolite2.mmdb 42bc99cb-8387-4918-ab49-5ab574a2b7ab
The tracer will create a table named TRACE the table looks like this
ID | HOP | IP | COUNTRY | CITY | ISP | LATITUDE | LONGITUDE | DATE_CREATED |
---|---|---|---|---|---|---|---|---|
d3aa1809-b729-4eab-8392-ffcf3a400510 | 1 | 19.19.19.19 | Argentina | Barranqueras | an_isp | 12.12 | 11.11 | 2020-12-04 19:26:15.220-030 |
Set the file systemd/tracer.service with the ip/host you want to traceroute.
sudo cp systemd/tracer.service /etc/systemd/system/tracer.service
sudo cp systemd/tracer.timer /etc/systemd/system/tracer.timer
sudo systemctl start tracer.timer
sudo systemctl enable --now tracer.timer
First you need setup an environment variable CSV_DATA with the path to you csv data.
$ export CSV_DATA=/PATH/TO/CSV/DATA
Then run the server
$ python -s dash_app.py
It will automatically open a new browser tab with the traces.
sqlite3 traces.sqlite
command to see traces
/> select * from traces;
Exit sqlite
/> .q
select CITY, ID, HOP, LONGITUDE, LATITUDE, IP, DATE_CREATED FROM TRACE WHERE LONGITUDE !='unknown' and LATITUDE != 'unknown' and id = "013ac729-e096-4bd5-8578-965dc7d27bd2" ORDER BY ID, HOP ASC limit 185;
sqlite3 traces.sqlite
Once you are in the sqlite command line type
/> .heards on
/> .mode csv
/> .output sample.csv
/> select CITY, ID, HOP, LONGITUDE, LATITUDE, IP, DATE_CREATED FROM TRACE WHERE LONGITUDE !='unknown' and LATITUDE != 'unknown' and id = "013ac729-e096-4bd5-8578-965dc7d27bd2" ORDER BY ID, HOP ASC limit 185;
No result are going to be display afte hit enter this is because your result went to the sample.csv.