From 26e7b1ff4e2de74aae073db12fe3f3e18ca7fdc6 Mon Sep 17 00:00:00 2001 From: Clark Winkelmann Date: Thu, 14 May 2015 14:34:09 +0200 Subject: [PATCH] First commit --- .gitignore | 3 + LICENSE | 22 +++++ README.md | 32 +++++++ nbproject/project.properties | 7 ++ nbproject/project.xml | 9 ++ network.example.json | 26 ++++++ server.php | 175 +++++++++++++++++++++++++++++++++++ start.sh | 3 + 8 files changed, 277 insertions(+) create mode 100644 .gitignore create mode 100644 LICENSE create mode 100644 README.md create mode 100644 nbproject/project.properties create mode 100644 nbproject/project.xml create mode 100644 network.example.json create mode 100644 server.php create mode 100755 start.sh diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..352a4a5 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +nbproject/private +*~ +network.json \ No newline at end of file diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..8b039b8 --- /dev/null +++ b/LICENSE @@ -0,0 +1,22 @@ +The MIT License (MIT) + +Copyright (c) 2015 Clark Winkelmann + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + diff --git a/README.md b/README.md new file mode 100644 index 0000000..a68bcbc --- /dev/null +++ b/README.md @@ -0,0 +1,32 @@ +# Simple Network Scanner + +This network scanner displays a list of the known and unknown devices on your LAN in a very simplist web page generated via PHP. + +Known devices are stored in a json file. The `arp-scan` command is used behind the scene to scan for running hosts. + +## How to use + +Install the `arp-scan` and `php5` packages. On Ubuntu you can use: + + sudo apt-get install arp-scan php5 + +Copy/rename `network.example.json` to `network.json` and add your known devices. +You can start with an empty file and add mac adresses after they appear in the "unknown" area of the GUI. + + cp network.example.json network.json + +Start the script in the PHP development server. +Root is required by the `arp-scan` command. + + sudo php -S localhost:8000 server.php + +or simply use the provided script (will prompt for your password): + + ./start.sh + +You can then access it in your browser by using the address given when starting the server. + +Note that a new scan is performed each time you refresh the page. +Also note that `arp-scan` does not always get a response from all hosts, causing them to be sometimes up or down. + +Currently the host performing the scan is not shown as up because the arp-scan does not return it. diff --git a/nbproject/project.properties b/nbproject/project.properties new file mode 100644 index 0000000..712f9b0 --- /dev/null +++ b/nbproject/project.properties @@ -0,0 +1,7 @@ +include.path=${php.global.include.path} +php.version=PHP_55 +source.encoding=UTF-8 +src.dir=. +tags.asp=false +tags.short=false +web.root=. diff --git a/nbproject/project.xml b/nbproject/project.xml new file mode 100644 index 0000000..2250349 --- /dev/null +++ b/nbproject/project.xml @@ -0,0 +1,9 @@ + + + org.netbeans.modules.php.project + + + Simple Network Scanner + + + diff --git a/network.example.json b/network.example.json new file mode 100644 index 0000000..16be063 --- /dev/null +++ b/network.example.json @@ -0,0 +1,26 @@ +{ + "devices": [{ + "name": "Router", + "type": "router", + "model": "Motorola Router", + "interfaces": [{ + "type": "eth", + "mac": "ab:cd:ef:01:23:45", + "ip": { + "type": "static", + "value": "192.168.1.1" + } + }] + },{ + "name": "Super PC", + "type": "pc", + "model": "ASUS Barebone", + "interfaces": [{ + "type": "eth", + "mac": "ab:cd:ef:01:23:45", + "ip": { + "type": "dhcp" + } + }] + }] +} \ No newline at end of file diff --git a/server.php b/server.php new file mode 100644 index 0000000..8bfa6fe --- /dev/null +++ b/server.php @@ -0,0 +1,175 @@ + $ip, + 'desc' => $desc, + 'known' => false, // Will be changed by the loop + ]; +} + +// Read network data from file +$network = json_decode(file_get_contents('network.json'), true); + +// Loop trough all described interfaces to mark them up or down +foreach($network['devices'] as $devicekey => $device) { + foreach($device['interfaces'] as $interfacekey => $interface) { + // Is this interface up ? + $up = false; + // IP of the interface (will remain null if neither defined or up) + $ipData = $network['devices'][$devicekey]['interfaces'][$interfacekey]['ip']; + $ip = array_key_exists('value', $ipData) ? $ipData['value'] : null; + $mac = $interface['mac']; + + // If the interface is up + if(array_key_exists($mac, $found_interfaces)) { + $up = true; + $ip = $found_interfaces[$mac]['ip']; + $found_interfaces[$mac]['known'] = true; + } + + // Save values for display + $network['devices'][$devicekey]['interfaces'][$interfacekey]['up'] = $up; + $network['devices'][$devicekey]['interfaces'][$interfacekey]['ip']['value'] = $ip; + } +} + +?> + + + + + + + + Simple Network Scanner + + + + +
+

Simple Network Scanner

+

Unknown devices

+
+ $interface): + if($interface['known']) { + // Here we only display unknown interfaces + continue; + } + ?> +
+
+
+
+
+
+
+
+
+ +
+

Network

+
+ +
+
+
+
+ +
+
+
+
+
+ +
+
+ +
+
+ + \ No newline at end of file diff --git a/start.sh b/start.sh new file mode 100755 index 0000000..0461b96 --- /dev/null +++ b/start.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +sudo php -S localhost:8000 server.php