Skip to content

Commit

Permalink
Merge pull request #18 from tux-00/develop
Browse files Browse the repository at this point in the history
Close #8
  • Loading branch information
tux-00 committed Aug 18, 2015
2 parents ad22a08 + a4e6453 commit 7435cb9
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 25 deletions.
12 changes: 2 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,26 +25,18 @@ Network Miner generates a network map by sending SNMP requests (LLDP/CDP/EDP).

Check [bower.io](http://bower.io/) website for more informations about Bower.

* Edit [data_mining.php](data_mining.php) and set the first hostname (or ip address) to scan at this line:

`$FIRST_DEVICE = 'test';`

and the dig level at this line (second parameter):

`recursive_search($FIRST_DEVICE, 1);`

* Run index.php in your web browser.

# Test files
You can test Network Miner without the appropriate environment.

To test Network Miner, you need first to copy the content of a json example data file (located in [test/data/](test/data/)) to your *data* directory.

Once the file is copied you need to comment these lines to avoid the scan and the overwrite of the data on *snmp_data.json*:
Once the file is copied you need to comment these lines to avoid the scan and the overwrite of the data on *snmp_data.json*:
```
recursive_search($FIRST_DEVICE, 1);
file_put_contents('./data/snmp_data.json', json_encode(array('nodes' => $nodes,
file_put_contents('./data/snmp_data.json', json_encode(array('nodes' => $nodes,
'links' => $links)),
LOCK_EX);
```
Expand Down
19 changes: 13 additions & 6 deletions data_mining.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
$devices = array();
// Correct OID to use
$OID_SELECTED = 0;
// First device to scan
$FIRST_DEVICE = 'test';

snmp_set_quick_print(TRUE);

Expand All @@ -31,12 +29,17 @@
*/
function get_oid() {
global $OIDS;
global $FIRST_DEVICE;

if ($_POST['community_input'] == '') {
$COMMUNITY = 'public';
} else {
$COMMUNITY = $_POST['community_input'];
}

if ($_POST['selected_proto'] != 'Auto') {
foreach ($OIDS as $name => $oid) {
if ($name == $_POST['selected_proto']) {
if (snmp2_walk($FIRST_DEVICE, 'public', $oid) != FALSE) {
if (snmp2_walk($_POST['ip_input'], $COMMUNITY, $oid) != FALSE) {
return $oid;
} else {
display_alert('danger', error_get_last()['message'] . '.');
Expand All @@ -48,7 +51,7 @@ function get_oid() {
}
if ($_POST['selected_proto'] == 'Auto') {
foreach ($OIDS as $name => $oid) {
$result = @snmp2_walk($FIRST_DEVICE, 'public', $oid);
$result = @snmp2_walk($_POST['ip_input'], 'public', $oid);
if ($result != FALSE) {
return $oid;
}
Expand Down Expand Up @@ -221,7 +224,11 @@ function display_alert($type, $content) {
exit(-1);
}

recursive_search($FIRST_DEVICE, 1);
$DIG_LEVEL = 1;
if ($_POST['dig_level_input'] != '') {
$DIG_LEVEL = $_POST['dig_level_input'];
}
recursive_search($_POST['ip_input'], $DIG_LEVEL);

file_put_contents('./data/snmp_data.json', json_encode(array('nodes' => $nodes,
'links' => $links)),
Expand Down
24 changes: 15 additions & 9 deletions functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@ $(document).ready(function() {
});

$('#discover_btn').click(function() {
discover();
if ($("#ip_input").val() == '') {
$('#ip_input').popover('show');
} else {
$('#ip_input').popover('hide');
discover();
}
});

$('#search_btn').click(function() {
Expand All @@ -17,29 +22,30 @@ $('#search_btn').click(function() {

$('.selectpicker').selectpicker();

$('#community_input').popover();
$('#dig_level_input').popover();

// Run algorythm to discover nodes/links and create map
function discover() {
jQuery.ajax({
type: 'POST',
url: 'data_mining.php',
data: {
selected_proto: $("#select_proto option:selected").text()
selected_proto: $("#select_proto option:selected").text(),
ip_input: $("#ip_input").val(),
community_input: $("#community_input").val(),
dig_level_input: $("#dig_level_input").val()
},
beforeSend: function(jqXHR, settings) {
$("#notif").html("");
$("svg").remove();
$(":input").prop('disabled', true);
$("#discover_btn").button('loading');
$("#discover_btn").prop('disabled', true);
$("#select_proto").prop('disabled', true);
$("#select_proto").selectpicker('refresh');
$("#search_btn").prop('disabled', true);
},
success: function(data, textStatus, jqXHR) {
$("#notif").html(data);
$(":input").prop('disabled', false);
$("#discover_btn").button('reset');
$("#select_proto").prop('disabled', false);
$("#select_proto").selectpicker('refresh');
$("#search_btn").prop('disabled', false);
rendering();
},
error: function(jqXHR, textStatus, errorThrown) {
Expand Down
3 changes: 3 additions & 0 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@
<option>CDP</option>
<option>EDP</option>
</select>
<input type="text" class="form-control" id="ip_input" placeholder="First IP/hostname..." data-placement="top" data-toggle="popover" data-content="Please enter an IP or hostname">
<input type="text" class="form-control" id="community_input" placeholder="Community..." data-placement="top" data-toggle="popover" data-trigger="hover" data-content="Default: public">
<input type="text" class="form-control" id="dig_level_input" placeholder="Dig level..." data-placement="top" data-toggle="popover" data-trigger="hover" data-content="Default: 1">
<div class="input-group pull-right">
<div class="scrollable-dropdown-menu">
<input type="text" class="form-control" id="search_input" autocomplete="off" placeholder="Device search...">
Expand Down

0 comments on commit 7435cb9

Please sign in to comment.