Skip to content

Instantly share code, notes, and snippets.

@sujayy1983
Created March 29, 2015 02:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sujayy1983/0610c50a61aac9e7395e to your computer and use it in GitHub Desktop.
Save sujayy1983/0610c50a61aac9e7395e to your computer and use it in GitHub Desktop.
+ System information and interface information. + This demo script is to obtain target information. + Any remote execution client can deploy this script and obtain info.
__author__='''Sujayyendhiren Srinivasamurthi'''
___email__='''sujayy1983@gmail.com'''
__description__= '''Demo script. Obtain target host's system information. '''
import platform
import logging
import netifaces
import socket
import json
import re
logging.basicConfig(filename='demoScript.log',level=logging.DEBUG)
class demoClass(object):
"""Demo class that obtains interface and system information."""
def __init__(self):
"""Initialize class variables."""
self.hostname = '\n--------------------------\nTarget hostname\n--------------------------\n'
self.listIfaces = '\n--------------------------\nList of all interfaces\n--------------------------\n'
self.sysInfo = '\n--------------------------\nSystem Information\n--------------------------\n'
self.ifaceInfo = '\n--------------------------\nInterface information\n--------------------------\n'
def get_platform_info(self):
""" Gets platform information and returns printable format."""
self.hostname += socket.gethostname() + "\n"
self.sysInfo += "\nOS: " + platform.system() + "\n"
self.sysInfo += "OS version: " + platform.version() + "\n"
self.sysInfo += "Python type: " + platform.python_implementation() + "\n"
self.sysInfo += "Python Implementation: " + platform.release() + "\n"
self.sysInfo += "Python version: " + str(platform.python_version_tuple()) + "\n"
logging.info(self.hostname)
logging.info(self.sysInfo)
def get_interface_info(self):
"""Obtains list of interfaces and its information."""
self.listIfaces += str( netifaces.interfaces() )
ifaces = netifaces.interfaces()
for iface in ifaces:
self.ifaceInfo += "Interface information: " + str(iface) + "\n" + json.dumps( netifaces.ifaddresses( iface ),indent=4)
logging.info(self.listIfaces)
logging.info(self.ifaceInfo)
if __name__ == "__main__":
obj = demoClass()
#OS and python information.
obj.get_platform_info()
#Get infterface information.
obj.get_interface_info()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment