Add initial linux support

formac
Cole Deck 2 years ago
parent 4fb575ba62
commit eb3d5c8910

@ -41,6 +41,16 @@ if win32:
_, username = res.strip().rsplit("\n", 1) _, username = res.strip().rsplit("\n", 1)
userid, sysdom = username.rsplit("\\", 1) userid, sysdom = username.rsplit("\\", 1)
if linux:
sysid = hex(uuid.getnode())
#fprint(sysid)
datafile += sysid
datafile += "gendata.csv"
res = subprocess.check_output(["who",], universal_newlines=True)
userid = res.strip().split(" ")[0]
sysdom = subprocess.check_output(["hostname",], universal_newlines=True)
#fprint(hostname)
def netstat_done(res): def netstat_done(res):
fprint("netstat done, processing") fprint("netstat done, processing")
procdata_res = pool.apply_async(netstat.process, (res,), callback=process_done) procdata_res = pool.apply_async(netstat.process, (res,), callback=process_done)
@ -114,7 +124,7 @@ class Logger(object):
sleep(0) sleep(0)
def flush(self): def flush(self):
print("") print("",end="")
if __name__ == '__main__': if __name__ == '__main__':
freeze_support() # required if packaged into single EXE freeze_support() # required if packaged into single EXE

@ -1,8 +1,9 @@
from util import find_data_file from util import find_data_file
from util import setup_child from util import setup_child
from util import fprint from util import fprint
from util import run_ps from util import run_cmd
from util import win32 from util import win32
from util import linux
import util import util
import time import time
import csv import csv
@ -69,12 +70,55 @@ def process(data):
writer.writerows(output2) writer.writerows(output2)
fprint("done creating csv") fprint("done creating csv")
if linux:
output = data.stdout.decode().split('\n') # split stdout into lines
output = [i for i in output if i]
if output[0].find("Not all processes could be identified") >= 0:
fprint("Not enough permissions")
raise PermissionError("Unable to acquire netstat data without admin!")
output2 = list()
for line in output:
string_split = line.split(" ")
string_split = [i for i in string_split if i]
#fprint("Input: " + str(string_split))
if string_split[0].find("Active") >= 0 or string_split[0].find("Proto") >= 0:
continue
if len(string_split) == 6: # no connection status
#fprint(string_split)
string_split.append(string_split[-1])
string_split[-2] = "UNKNOWN"
#fprint(string_split)
procname = string_split[6]
if procname != "-":
string_split2 = procname.split("/")
procname = string_split2[1]
pid = string_split2[0]
else:
pid = "Unknown"
output2.append([procname, string_split[0], string_split[3], string_split[4], string_split[5], pid])
#fprint(output2)
with open(find_data_file(util.datafile), "w", newline="") as f:
writer = csv.writer(f)
writer.writerows(output2)
fprint("done creating csv")
def start(): def start():
fprint("netstat started")
setup_child() setup_child()
fprint("netstat started")
if win32: if win32:
data = run_ps("netstat -n -o -b") data = run_cmd("netstat -n -o -b")
fprint("data acquired")
return data
if linux:
data = run_cmd("netstat -atunpw")
fprint("data acquired") fprint("data acquired")
return data return data

File diff suppressed because one or more lines are too long

@ -0,0 +1,4 @@
fabric
paramiko
wxpython
cx_Freeze

@ -12,10 +12,15 @@ base = None
if sys.platform == "win32" and not debug: if sys.platform == "win32" and not debug:
base = "Win32GUI" base = "Win32GUI"
if sys.platform == "linux" or sys.platform == "linux2" or sys.platform == "darwin":
name = "IPPigeon"
else:
name = "IPPigeon.exe"
setup( setup(
name="IP Pigeon", name="IP Pigeon",
version="0.2.4", version="0.2.4",
description="IP Pigeon client application", description="IP Pigeon client application",
options={"build_exe": build_exe_options}, options={"build_exe": build_exe_options},
executables=[Executable("ippigeon.py", base=base, icon="icon.ico", uac_admin=True, target_name="IPPigeon.exe")], executables=[Executable("ippigeon.py", base=base, icon="icon.ico", uac_admin=True, target_name=name)],
) )

@ -7,6 +7,7 @@ from sys import platform
import sys import sys
from util import find_data_file from util import find_data_file
from util import fprint from util import fprint
from util import setup_child
TRAY_TOOLTIP = 'IP Pigeon' TRAY_TOOLTIP = 'IP Pigeon'
@ -67,9 +68,11 @@ class TaskbarApp(wx.App):
frame=wx.Frame(None) frame=wx.Frame(None)
self.SetTopWindow(frame) self.SetTopWindow(frame)
TaskBarIcon(frame) TaskBarIcon(frame)
return True return True
def background(data, sets, kill): def background(data, sets, kill):
setup_child()
global killme global killme
global settings global settings
global displaydata global displaydata
@ -77,6 +80,10 @@ def background(data, sets, kill):
app = TaskbarApp(False) app = TaskbarApp(False)
displaydata = data displaydata = data
settings = sets settings = sets
fprint("Creating taskbar icon")
app.MainLoop() app.MainLoop()
TRAY_ICON = find_data_file('icon.png') TRAY_ICON = find_data_file('icon.png')
if __name__ == "__main__":
background(list(), dict(), int())

@ -0,0 +1,94 @@
#!/usr/bin/env pythonw
import wx
import wx.adv
import wx.lib.embeddedimage
WXPdemo = wx.lib.embeddedimage.PyEmbeddedImage(
"iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAABHNCSVQICAgIfAhkiAAAAWlJ"
"REFUWIW1V1sSwjAIBMebeBU9db2KZ8EPmxbCI4TUnXGskWaXDQktwhjErjERP4XRhER08iPi"
"5SKiyQR5JyI7xxB3j7wn5GI6V2hFxM0gJtjYANFBiIjQu7L/1lYlwR0QxLDZhE0II1+CtwRC"
"RI8riBva7DL7CC9VAwDbbxwKtdDXwBi7K+1zCP99T1vDFedd8FBwYd6BCAUXuACEF7QsbET/"
"FaHs+gDQw4vOLNHkMojAnTw8nlNipIiwmR0DCXJbjCXkFCAL23BnpQgRWt1EMbyujCK9AZzZ"
"f+b3sX0oSqJQ6EorFeT4NiL6Wtj0+LXnQAzThYoAAsN6ehqR3sHExmcEqGeFApQLcTvm5Kt9"
"wkHGgb+RZwSkyc1dwOcpCtCoNKSz6FRCUQ3o7Nn+5Y+Lg+y5CIXlcyAk99ziiQS32+svz/UY"
"vClJoLpIC8gi+VwwfDecEiEtT/WZTJDf94uk1Ru8vbz0cvoF7S2DnpeVL9UAAAAASUVORK5C"
"YII=")
class DemoTaskBarIcon(wx.adv.TaskBarIcon):
TBMENU_RESTORE = wx.NewId()
TBMENU_CLOSE = wx.NewId()
TBMENU_CHANGE = wx.NewId()
TBMENU_REMOVE = wx.NewId()
def __init__(self, frame):
wx.adv.TaskBarIcon.__init__(self)
self.frame = frame
# Set the image
icon = self.MakeIcon(WXPdemo.GetImage())
self.SetIcon(icon, "wxPython Demo")
self.imgidx = 1
# bind some events
self.Bind(wx.adv.EVT_TASKBAR_LEFT_DCLICK, self.OnTaskBarActivate)
self.Bind(wx.EVT_MENU, self.OnTaskBarActivate, id=self.TBMENU_RESTORE)
self.Bind(wx.EVT_MENU, self.OnTaskBarClose, id=self.TBMENU_CLOSE)
def CreatePopupMenu(self):
"""
This method is called by the base class when it needs to popup
the menu for the default EVT_RIGHT_DOWN event. Just create
the menu how you want it and return it from this function,
the base class takes care of the rest.
"""
menu = wx.Menu()
menu.Append(self.TBMENU_RESTORE, "Restore wxPython Demo")
menu.Append(self.TBMENU_CLOSE, "Close wxPython Demo")
return menu
def MakeIcon(self, img):
"""
The various platforms have different requirements for the
icon size...
"""
if "wxMSW" in wx.PlatformInfo:
img = img.Scale(16, 16)
elif "wxGTK" in wx.PlatformInfo:
img = img.Scale(22, 22)
# wxMac can be any size upto 128x128, so leave the source img alone....
icon = wx.Icon("icon.png")
#self.SetIcon(icon, TRAY_TOOLTIP)
return icon
def OnTaskBarActivate(self, evt):
if self.frame.IsIconized():
self.frame.Iconize(False)
if not self.frame.IsShown():
self.frame.Show(True)
self.frame.Raise()
def OnTaskBarClose(self, evt):
wx.CallAfter(self.frame.Close)
class MainFrame(wx.Frame):
def __init__(self, parent):
wx.Frame.__init__(self, parent, title="Hello World")
self.tbicon = DemoTaskBarIcon(self)
self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)
def OnCloseWindow(self, evt):
self.tbicon.Destroy()
evt.Skip()
app = wx.App(redirect=False)
frame = MainFrame(None)
frame.Show(True)
app.MainLoop()

@ -25,6 +25,16 @@ if win32:
_, username = res.strip().rsplit("\n", 1) _, username = res.strip().rsplit("\n", 1)
userid, sysdom = username.rsplit("\\", 1) userid, sysdom = username.rsplit("\\", 1)
if linux:
sysid = hex(uuid.getnode())
#fprint(sysid)
datafile += sysid
datafile += "gendata.csv"
res = subprocess.check_output(["who",], universal_newlines=True)
userid = res.strip().split(" ")[0]
sysdom = subprocess.check_output(["hostname",], universal_newlines=True)
#fprint(hostname)
def time(): def time():
return int(t.time()) return int(t.time())
@ -35,12 +45,12 @@ def fprint(msg):
frm = inspect.stack()[1] frm = inspect.stack()[1]
mod = inspect.getmodule(frm[0]) mod = inspect.getmodule(frm[0])
print('[' + mod.__name__ + ":" + frm.function + ']:', msg) print('[' + mod.__name__ + ":" + frm.function + ']:', str(msg))
except Exception as e: except Exception as e:
try: try:
print('[????:' + frm.function + ']:', msg) print('[????:' + frm.function + ']:', str(msg))
except: except:
print('[????]:', msg) print('[????]:', str(msg))
# else: # else:
@ -56,8 +66,7 @@ def find_data_file(filename):
datadir = os.path.dirname(__file__) datadir = os.path.dirname(__file__)
return os.path.join(datadir, filename) return os.path.join(datadir, filename)
def run_ps(cmd): def run_cmd(cmd):
fprint("init PS")
if win32: if win32:
startupinfo = subprocess.STARTUPINFO() startupinfo = subprocess.STARTUPINFO()
#print("DICKS") #print("DICKS")
@ -72,7 +81,11 @@ def run_ps(cmd):
completed = subprocess.run(["powershell", "-Command", cmd], capture_output=True, startupinfo=startupinfo) completed = subprocess.run(["powershell", "-Command", cmd], capture_output=True, startupinfo=startupinfo)
fprint("ran PS command successfully") fprint("ran PS command successfully")
#completed = subprocess.run(["powershell", "-WindowStyle", "hidden", "-Command", cmd], capture_output=True, startupinfo=startupinfo) #completed = subprocess.run(["powershell", "-WindowStyle", "hidden", "-Command", cmd], capture_output=True, startupinfo=startupinfo)
return completed
if linux:
fprint("running sh command: " + cmd)
completed = subprocess.run(["sh", "-c", cmd], capture_output=True)
fprint("ran sh command successfully")
return completed return completed
def setup_child(): def setup_child():
@ -95,4 +108,4 @@ class Logger(object):
sleep(0) sleep(0)
def flush(self): def flush(self):
print("") print("", end="")
Loading…
Cancel
Save