def get_default_gateway_ip(): """ Returns the IP address of the currently connected gateway """ netstat = shell_out("netstat -nr") for i in netstat: if i.startswith("default"): return filter(None, i.split(' '))[1]
def get_default_gateway_mac(): """ Returns the MAC address of the currently connected gateway """ ip_addr = get_default_gateway_ip() arp = shell_out("arp -an") for i in arp: if ("(%s)" % ip_addr) in i: return i.split(' ')[3]
def get_documents(): """ Find all document files on the system with mdfind """ files = [] file_extensions = ["docx", "doc", "xlsx", "xls", "pptx", "ppt", "pdf", "key", "pages", "numbers"] for ext in file_extensions: arg = "kMDItemDisplayName == *.%s" % (ext,) files += shell_out("mdfind %s" % (arg,)) return filter(None, files)
def ssh_length(): """ Returns an array of times that open ssh connections have been open """ ssh_times = [] ps_ax = shell_out("ps -ax -o etime,command -c") for i in ps_ax: data = i.strip().strip('\n').split(' ') if len(data) == 2 and data[-1] == 'ssh': ssh_times.append(data[0]) return ssh_times
def get_ssid(): """ Returns the currently connected SSID """ command = "".join([ "System/Library/PrivateFrameworks/Apple80211.framework/Versions/", "Current/Resources/airport -I", ]) airport = shell_out(command) for i in airport: if re.match(r'^SSID:', i.strip()): return i.strip().strip("SSID: ")
def get_documents(): """ Find all document files on the system with mdfind """ files = [] file_extensions = [ "docx", "doc", "xlsx", "xls", "pptx", "ppt", "pdf", "key", "pages", "numbers" ] for ext in file_extensions: arg = "kMDItemDisplayName == *.%s" % (ext, ) files += shell_out("mdfind %s" % (arg, )) return filter(None, files)
def find_ssh_keys(): """ Returns an array of SSH private keys on the host """ keys = [] keys1 = shell_out("mdfind kMDItemFSName=='id_*sa'") if keys1: for key in keys1: if key and not match("^/Users/[a-zA-Z0-9]*/.ssh", key): keys.append(key) keys2 = shell_out("mdfind kMDItemFSName=='*.id'") if keys2: for key in keys2: try: if isfile(key) and is_ssh_key(key): keys.append(key) except OSError: pass except Exception: pass return keys
def scutil_dns(): """ Returns a dictinoary with the search domain, nameserver0 and nameserver1 """ scutil_command = shell_out("scutil --dns") scutil = {} if scutil_command: for i in scutil_command: j = filter(None, i.split(" ")) if 'domain[0]' in j: scutil['search_domain'] = j[-1] continue elif 'nameserver[0]' in j: scutil['nameserver0'] = j[-1] continue elif 'nameserver[1]' in j: scutil['nameserver1'] = j[-1] continue return scutil
def get_ifconfig(): """ Returns a JSON array of `ifconfig` """ ifconfig = shell_out("ifconfig -a") json = {} if ifconfig: for i in ifconfig: if not i.startswith('\t'): interface = i.split(':')[0] json[interface] = {} curr = interface else: i = i[1:] i_space = i.find(' ') i_equals = i.find('=') greater_than = i_space if i_space > i_equals else i_equals k = i[:greater_than].strip(':') j = i[greater_than:].split(' ') if j[0] == '': j = j[1::] json[curr][k] = j return json
def get_executables(): """ Find all executable files on the system with mdfind """ return shell_out("mdfind kMDItemContentType==public.unix-executable")