Python Script to Scan Listener Log For Incoming Connections

Wrote a quick and dirty script to scan the listener log for incoming connections and produce a count of how many connections came from which host. Here is the URL:

https://github.com/bobbydurrett/miscpython/blob/master/gethostcounts.py

All it does is hack out the ip address from the second HOST= entry of the lines in the listener log that have HOST= in them. Then it uses the Python function socket.gethostbyaddr to get the hostname for those that can be looked up this way.

Counts the number of lines for a given ip address and sorts them from most to least connections. Might be useful to someone.

Bobby

About Bobby

I live in Chandler, Arizona with my wife and three daughters. I work for US Foods, the second largest food distribution company in the United States. I have worked in the Information Technology field since 1989. I have a passion for Oracle database performance tuning because I enjoy challenging technical problems that require an understanding of computer science. I enjoy communicating with people about my work.
This entry was posted in Uncategorized. Bookmark the permalink.

4 Responses to Python Script to Scan Listener Log For Incoming Connections

  1. Tim N. says:

    Unix shell version … if I translated correctly … YMMV 🙂

    =====
    cat ${ORACLE_BASE}/diag/tnslsnr/myhost/listener/trace/listener.log | grep -E ‘\(HOST=’ | tr -s ‘ ‘ | cut -d ‘*’ -f3 | sed -e ‘s#^ (A#(A#g’ | cut -d ‘=’ -f4 | sed -e ‘s#)(PORT##g’ | grep -E ‘^[1-9]’ | sort | uniq –count | sort -s -n -k 1,1

    Tim…

  2. Arun says:

    Great.

    Is there a shell script to shut and start the database and listener.

    • Bobby says:

      From Python? I don’t have a Python script for that but someone could make one using subprocess to run the necessary shell scripts. Thanks for your comment.

      Bobby

Leave a Reply to Tim N. Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.