func/minion

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



 func/minion/modules/portinfo.py |   46 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 46 insertions(+)

New commits:
commit 45a6eff11f8f91a4ddb99f5db859b0a716b44e54
Author: Jan-Frode Myklebust <janfrode@xxxxxxxxx>
Date:   Mon May 9 16:35:08 2011 -0400

    module for keeping inventory of which network ports
    a minion is listening on.

diff --git a/func/minion/modules/portinfo.py b/func/minion/modules/portinfo.py
new file mode 100644
index 0000000..d456ec5
--- /dev/null
+++ b/func/minion/modules/portinfo.py
@@ -0,0 +1,46 @@
+#
+# Copyright 2011
+# Jan-Frode Myklebust <janfrode@xxxxxxxxx> -- 2011
+#
+# This software may be freely redistributed under the terms of the GNU
+# general public license.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+import func_module
+import sub_process
+
+class PortinfoModule(func_module.FuncModule):
+
+    version = "0.0.1"
+    api_version = "0.0.1"
+    description = "Informations on active network ports."
+
+    def inventory(self):
+        """
+        Returns information on all network ports in LISTEN state.
+        """
+        return "\n".join(self.listenports()) + "\n"
+
+    def listenports(self):
+        """
+        Returns the adresses and ports a host is listening on.
+        """
+
+        cmd = sub_process.Popen(["netstat", "-nl"],shell=False,stdout=sub_process.PIPE,close_fds=True)
+        data = cmd.communicate()[0]
+
+        ports = []
+        tcpports = []
+        udpports = []
+        for line in data.splitlines():
+              if line.split()[0]=="tcp":
+                    tcpports.append(line.split()[3] + "/tcp")
+              elif line.split()[0]=="udp":
+                    udpports.append(line.split()[3] + "/udp")
+        tcpports.sort()
+        udpports.sort()
+        ports = tcpports + udpports
+        return ports


_______________________________________________
Func-list mailing list
Func-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/func-list


[Index of Archives]     [Fedora Users]     [Linux Networking]     [Fedora Legacy List]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]

  Powered by Linux