Getting Data In

Anyone setup a netstat like input for Windows?

Lowell
Super Champion

Has anyone setup the windows "netstat" command as an input?

I like the "netstat" source provided in the unix app, and it seems like it should be possible to capture most of the same information using the built-in "netstat.exe" that comes with windows. I did notice that some of the columns are too wide (long host names or port names).

Is there a way to get the same information with a WMI source?

hazekamp
Builder

ESS currently does this in python. We will be loooking to use something else now that the Universal Forwarder doesn't have python. The following python can be saved and run by Splunk as a scripted input:

'''
Copyright (C) 2005-2011 Splunk Inc. All Rights Reserved.
'''
from time import gmtime, strftime
import subprocess
import re
import string
import hashlib

# set blank event
event = ''
netstat = False
ports = []
netstat_hash = ''
tempPorts = []
tempPort = ''

event = strftime('%b %d %Y %H:%M:%S') + ' '

try:
    netstat = subprocess.Popen(['netstat', '-nao'], stdout=subprocess.PIPE)

except:
        pass

if netstat:
    # run chkconfig command and split the output into a list
    ports = netstat.communicate()[0]
    ports = ports.split('\n')
    # remove header
    ports = ports[1:len(ports)]

    validRE = re.compile('LISTENING|UDP', re.I)
    hostRE = re.compile('(.*)\:(\d+)')

    for port in ports:

        tempEvent = event
        tempPort = ''
        validMatch = validRE.search(port)

        if validMatch:

            port = port.strip()
            port = port.split()
            # trim port array for lines with (LISTEN)

            hostMatch = hostRE.match(port[1])

            tempEvent += ' transport=' + port[0].strip()
            tempPort += port[0].strip()

            if hostMatch:
                tempEvent += ' dest_ip=' + hostMatch.group(1).strip()
                tempPort += hostMatch.group(1).strip()
                tempEvent += ' dest_port=' + hostMatch.group(2).strip()
                tempPort += hostMatch.group(2).strip()


                if len(port) == 5:
                    tempEvent += ' pid=' + port[4]
                elif len(port) == 4:
                    tempEvent += ' pid=' + port[3]

                print tempEvent
                tempPorts.append(tempPort)

if tempPorts:
    netstat = string.join(tempPorts, '')
    netstat_hash = hashlib.sha1(netstat).hexdigest()

    print event + 'file_hash=' + netstat_hash
0 Karma

gkanapathy
Splunk Employee
Splunk Employee

I do not believe there is any standard way to get netstat (I'm assuming you mean process/port info, not interface stats) using WMI.

0 Karma

Lowell
Super Champion

That is correct. I'm looking for connected ports and listening ports, and seeing the PIDs is nice too. I think netstat -a -o will give me a good place to start.

0 Karma
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.

Can’t make it to .conf25? Join us online!

Get Updates on the Splunk Community!

Splunk Lantern’s Guide to The Most Popular .conf25 Sessions

Splunk Lantern is a Splunk customer success center that provides advice from Splunk experts on valuable data ...

Unlock What’s Next: The Splunk Cloud Platform at .conf25

In just a few days, Boston will be buzzing as the Splunk team and thousands of community members come together ...

Index This | How many sevens are there between 1 and 100?

August 2025 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with this ...