-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
186 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
Name = GeoIP | ||
Author = Beercow | ||
Description = Adds geoip data to details | ||
Version = 0.1 | ||
Type = EventHandler | ||
Architecture = LinuxShellScript | ||
File = GeoIP.py | ||
Priority = 9 | ||
RunHidden = 0 | ||
RunExclusively = 1 | ||
CanOverrideOtherPlugins = 0 | ||
CanOverrideProcdot = 0 | ||
Event = AfterRefresh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
#!/usr/bin/env python | ||
|
||
import os | ||
import pygeoip | ||
import sys | ||
import urllib | ||
import gzip | ||
|
||
reload(sys) | ||
sys.setdefaultencoding('utf8') | ||
out = os.getenv('PROCDOTPLUGIN_ResultTXT') | ||
|
||
def database(url,dbgz,db): | ||
geo = urllib.URLopener() | ||
try: | ||
geo.retrieve(url, dbgz) | ||
with gzip.open(dbgz, 'rb') as infile: | ||
with open(db, 'wb') as outfile: | ||
for line in infile: | ||
outfile.write(line) | ||
os.remove(dbgz) | ||
except Exception as e: | ||
open(out, 'wb').write(str(e)) | ||
sys.exit(0) | ||
|
||
if os.path.isfile('GeoLiteCity.dat'): | ||
pass | ||
else: | ||
database('http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz', 'GeoLiteCity.dat.gz', 'GeoLiteCity.dat') | ||
|
||
if os.path.isfile('GeoIPASNum.dat'): | ||
pass | ||
else: | ||
database('http://download.maxmind.com/download/geoip/database/asnum/GeoIPASNum.dat.gz', 'GeoIPASNum.dat.gz', 'GeoIPASNum.dat') | ||
|
||
tfolder = os.listdir(os.getenv('PROCDOTPLUGIN_TempFolder')) | ||
details = open(os.getenv('PROCDOTPLUGIN_GraphFileDetails'),'rb').readlines() | ||
n = open(os.getenv('PROCDOTPLUGIN_GraphFileDetails'),'w') | ||
|
||
for num, line in enumerate(details,1): | ||
if 'IP-Address' in line: | ||
query = pygeoip.GeoIP('GeoLiteCity.dat') | ||
asn = pygeoip.GeoIP('GeoIPASNum.dat') | ||
x = [x.strip() for x in line.split(' ')][2] | ||
try: | ||
results = query.record_by_addr(x) | ||
asn_info = asn.asn_by_addr(x) | ||
for key, val in results.items(): | ||
details.insert(num,str(key) + ' = ' + str(val) + '\n') | ||
|
||
try: | ||
details.insert(num,'asn = '+asn_info+'\n') | ||
except: | ||
pass | ||
except: | ||
pass | ||
details = "".join(details) | ||
n.write(details) | ||
n.close() | ||
sys.exit(0) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# GeoIP | ||
|
||
## Project source can be downloaded from | ||
|
||
## Author & Contributor List | ||
Brian Maloney | ||
|
||
## Overview | ||
This plugin adds geographical information to server nodes. GeoIP is an event hadler plugin so you will not see anything added to the graph or plugin menus. It is designed to run after the refresh button is clicked. The first run of GeoIP, you might have a slight delay because teh plugin needs to download the Maxmind database. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
@setlocal enabledelayedexpansion && C:\Python27\python.exe -x "%~f0" %* & exit /b !ERRORLEVEL! | ||
#!/usr/bin/env python | ||
|
||
import os | ||
import pygeoip | ||
import sys | ||
import urllib | ||
import gzip | ||
|
||
reload(sys) | ||
sys.setdefaultencoding('utf8') | ||
out = os.getenv('PROCDOTPLUGIN_ResultTXT') | ||
|
||
def database(url,dbgz,db): | ||
geo = urllib.URLopener() | ||
try: | ||
geo.retrieve(url, dbgz) | ||
with gzip.open(dbgz, 'rb') as infile: | ||
with open(db, 'wb') as outfile: | ||
for line in infile: | ||
outfile.write(line) | ||
os.remove(dbgz) | ||
except Exception as e: | ||
open(out, 'wb').write(str(e)) | ||
sys.exit(0) | ||
|
||
if os.path.isfile('GeoLiteCity.dat'): | ||
pass | ||
else: | ||
database('http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz', 'GeoLiteCity.dat.gz', 'GeoLiteCity.dat') | ||
|
||
if os.path.isfile('GeoIPASNum.dat'): | ||
pass | ||
else: | ||
database('http://download.maxmind.com/download/geoip/database/asnum/GeoIPASNum.dat.gz', 'GeoIPASNum.dat.gz', 'GeoIPASNum.dat') | ||
|
||
tfolder = os.listdir(os.getenv('PROCDOTPLUGIN_TempFolder')) | ||
details = open(os.getenv('PROCDOTPLUGIN_GraphFileDetails'),'rb').readlines() | ||
n = open(os.getenv('PROCDOTPLUGIN_GraphFileDetails'),'w') | ||
|
||
for num, line in enumerate(details,1): | ||
if 'IP-Address' in line: | ||
query = pygeoip.GeoIP('GeoLiteCity.dat') | ||
asn = pygeoip.GeoIP('GeoIPASNum.dat') | ||
x = [x.strip() for x in line.split(' ')][2] | ||
try: | ||
results = query.record_by_addr(x) | ||
asn_info = asn.asn_by_addr(x) | ||
for key, val in results.items(): | ||
details.insert(num,str(key) + ' = ' + str(val) + '\n') | ||
|
||
try: | ||
details.insert(num,'asn = '+asn_info+'\n') | ||
except: | ||
pass | ||
except: | ||
pass | ||
details = "".join(details) | ||
n.write(details) | ||
n.close() | ||
sys.exit(0) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
Name = GeoIP | ||
Author = Beercow | ||
Description = Adds geoip data to details | ||
Version = 0.1 | ||
Type = EventHandler | ||
Architecture = WindowsBatchScript | ||
File = GeoIP.bat | ||
Priority = 9 | ||
RunHidden = 0 | ||
RunExclusively = 1 | ||
CanOverrideOtherPlugins = 0 | ||
CanOverrideProcdot = 0 | ||
Event = AfterRefresh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# -*- mode: python -*- | ||
|
||
block_cipher = None | ||
|
||
|
||
a = Analysis(['GeoIP.py'], | ||
pathex=['/home/remnux/Desktop/procdot/lin64/plugins'], | ||
binaries=[], | ||
datas=[], | ||
hiddenimports=[], | ||
hookspath=[], | ||
runtime_hooks=[], | ||
excludes=[], | ||
win_no_prefer_redirects=False, | ||
win_private_assemblies=False, | ||
cipher=block_cipher) | ||
pyz = PYZ(a.pure, a.zipped_data, | ||
cipher=block_cipher) | ||
exe = EXE(pyz, | ||
a.scripts, | ||
a.binaries, | ||
a.zipfiles, | ||
a.datas, | ||
name='GeoIP', | ||
debug=False, | ||
strip=False, | ||
upx=True, | ||
runtime_tmpdir=None, | ||
console=False ) |