From 2d134ce6fc2d2010e2c4fe3d268b39d2b9b5b78b Mon Sep 17 00:00:00 2001 From: DefunctLizard Date: Sat, 19 Dec 2020 00:08:08 -0700 Subject: [PATCH] finish issues with JSON --- README.md | 15 ++++++++------- data/map.js | 4 ++-- src/ip.rs | 6 +++++- src/main.rs | 2 +- test | 3 +++ 5 files changed, 19 insertions(+), 11 deletions(-) create mode 100644 test diff --git a/README.md b/README.md index 6de272d..4d40477 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,8 @@

ipmap

-

-An interactive map that shows connected IP addresses. - -

+

An interactive map that shows connected IP addresses.

+
+

## Requirements ipmap uses `libpcap-dev`, which is only easily available on UNIX-like systems (Linux, MacOS, *BSD). @@ -49,8 +48,8 @@ If no service specified, ipapi will be used, which will limit how many IP is det ## Command Line Options ``` -ipmap 0.1.2 -Skyline High School Coding Club Authors +ipmap 0.1.5 +Skyline High Coding Club Authors USAGE: ipmap [FLAGS] [OPTIONS] @@ -61,5 +60,7 @@ FLAGS: -V, --version Prints version information OPTIONS: - -s, --service Geolocation API + -p, --port Set webserver port, default port 700 + -s, --service Choose Geolocation API [possible values: ipwhois, ipapi, ipapico, freegeoip] + -w, --write-to-file Set path to write JSON to ``` diff --git a/data/map.js b/data/map.js index d0e4aaf..703df27 100644 --- a/data/map.js +++ b/data/map.js @@ -8,7 +8,7 @@ var alreadyAdded = new Set(); function addMarkers(jsonText) { console.log(jsonText) - for(var i = 1; i < jsonText.length; i++) { + for(var i = 0; i < jsonText.length; i++) { var obj = jsonText[i]; if (alreadyAdded.has(obj.ip)) { @@ -17,7 +17,7 @@ function addMarkers(jsonText) { console.log(obj.ip); - document.getElementById("totalIps").innerHTML = jsonText.length - 1 + " Unique IP's"; + document.getElementById("totalIps").innerHTML = jsonText.length + " Unique IP's"; L.marker([obj.latitude, obj.longitude]).addTo(ipmap) // .bindpopup(obj.ip); diff --git a/src/ip.rs b/src/ip.rs index 6e59c4d..0fc3aca 100644 --- a/src/ip.rs +++ b/src/ip.rs @@ -265,7 +265,11 @@ pub fn get_document() -> String { json.push_str("[\n"); - for a in &*IP_MAP.read().unwrap() { + let v = &*IP_MAP.read().unwrap(); + + let iter = v[1..].iter(); + + for a in iter { let address = IPAddress { ip: a[0].to_owned(), latitude: a[1].to_owned(), diff --git a/src/main.rs b/src/main.rs index 6d9d02b..7070f07 100644 --- a/src/main.rs +++ b/src/main.rs @@ -59,7 +59,7 @@ fn main() { Arg::with_name("port") .long("port") .short("p") - .help("Set webserver port, default port 700") + .help("Set webserver port, if not set it defaults to port 700") .required(false) .takes_value(true) .value_name("PORT"), diff --git a/test b/test new file mode 100644 index 0000000..d63a6b9 --- /dev/null +++ b/test @@ -0,0 +1,3 @@ +[ +{"ip":"193.148.18.75","latitude":"40.7157","longitude":"-74"} +]