Commit 5141f71e authored by Leo Leung's avatar Leo Leung
Browse files

Added helper scripts

Added missing iso3166 dependency to composer
parent ff57d15b
......@@ -14,6 +14,7 @@
"require": {
"php": ">=5.6.0",
"julien-c/iso3166": "*",
"geoip2/geoip2": "~2.0"
},
......
......@@ -2,11 +2,15 @@
namespace Steamr\NetworkUtilities;
use \Iso3166\Codes;
use GeoIp2\Database\Reader;
class AddressLookup
{
private $asn_db = "/network/GeoLite2-ASN.mmdb";
private $city_db = "/network/GeoLite2-City.mmdb";
// not an exhaustive list
private $reserved_ips = [
['start' => '0.0.0.0', 'end' => '0.255.255.255', 'reason' => 'software subnet',],
......@@ -27,9 +31,6 @@ class AddressLookup
['start' => '255.255.255.255', 'end' => '255.255.255.255', 'reason' => 'limited broadcast',]
];
private $asn_db = "/geoip/GeoLite2-ASN.mmdb";
private $city_db = "/geoip/GeoLite2-City.mmdb";
/**
* Handles a MAC address lookup
* @param $input must be a MAC address
......@@ -145,4 +146,4 @@ class AddressLookup
return "";
}
}
\ No newline at end of file
}
......@@ -5,7 +5,7 @@ namespace Steamr\NetworkUtilities;
class MacLookup
{
private $ouiFile = "/oui/parsed.txt";
private $ouiFile = "network/mac_addresses.txt";
/**
* Handles a MAC address lookup
......@@ -108,4 +108,4 @@ class MacLookup
$input[8] . $input[9] . ":" .
$input[10] . $input[11];
}
}
\ No newline at end of file
}
# There are two databases that are used. Because there is no AS number db for geolite2,
# we'll have to use both the new and legacy databases.
#
# The databases are available from MaxMind at:
#
# http://dev.maxmind.com/geoip/geoip2/geolite2/
# * http://geolite.maxmind.com/download/geoip/database/GeoLite2-City.mmdb.gz
#
# http://dev.maxmind.com/geoip/legacy/geolite/
# * http://download.maxmind.com/download/geoip/database/asnum/GeoIPASNum.dat.gz
test -d download || mkdir download
cd download
wget http://geolite.maxmind.com/download/geoip/database/GeoLite2-City.mmdb.gz
wget https://geolite.maxmind.com/download/geoip/database/GeoLite2-ASN.tar.gz
gunzip GeoLite2-City.mmdb.gz
tar -xzf GeoLite2-ASN.tar.gz
mv GeoLite2-ASN*/*mmdb .
cp *mmdb ..
cd ..
rm -rf download
<?php
$fp = fopen("oui.txt", "r");
while (($str = fgets($fp, 4096)) !== false) {
$str = trim($str);
if (strlen($str) < 10) continue;
if ($str[2] == '-' && $str[5] == '-') {
// this line is hex, next bas64+ company, address, city/prov/postal, country
// next line
$str = fgets($fp, 4096);
$parts = preg_split('/\s+/', $str);
echo $parts[0] . "|";
unset($parts[0]);
unset($parts[1]);
unset($parts[2]);
echo trim(implode(" ", $parts)) . "|";
$str = fgets($fp, 4096);
if (trim($str) == "") {
echo "\n";
continue;
}
echo trim($str) . "|";
$str = fgets($fp, 4096);
echo trim($str) . "|";
$str = fgets($fp, 4096);
echo trim($str) . "\n";
}
}
#!/bin/bash
wget https://linuxnet.ca/ieee/oui.txt
php parse_oui.php | sort > mac_addresses.txt
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment