Getting Data In

Poking TCP Ports from Windows PowerShell

ShaneNewman
Motivator

A vendor is requesting that we Poke several TCP ports and send specific text to capture application status. "Poke 8080, send http GET for / and Poke TCP 5222 and send string 'test123'".

I know how to use powershell to initiate a telnet connection to the ports and monitor port status that way:

$Port = 8080,5222,5223
foreach ($P in $Port) {
$Socket = New-Object Net.Sockets.TcpClient
$Computer = "LocalHost"
$RunTime = get-date

# Suppress error messages
$ErrorActionPreference = 'SilentlyContinue'

# Try to connect
$Socket.Connect($Computer, $P)

# Determine if we are connected.
if ($Socket.Connected) {
 "$RunTime Port $P is open"
  $Socket.Close()   
  }
  else {
  "$RunTime Port $P is closed" 
  }
  }
  $Socket = $null

How can I modify this code to also pass a text string or command?

1 Solution

halr9000
Motivator

I would suggesting thinking one layer higher. Test the service, not the TCP protocol. 5222 is WS-Man, aka PowerShell remoting. There's a cmdlet for that, and yes, you can invoke it from Splunk. Check out:

HTH

View solution in original post

halr9000
Motivator

I would suggesting thinking one layer higher. Test the service, not the TCP protocol. 5222 is WS-Man, aka PowerShell remoting. There's a cmdlet for that, and yes, you can invoke it from Splunk. Check out:

HTH

halr9000
Motivator

I'd post this to serverfault, TechNet forums, /r/powershell, or the like. That said...

0 Karma

ShaneNewman
Motivator

I found that and tried it to no avail. I was hoping that someone on the forum had tried to do something similar and found a way to do it from Splunk or had created app with a built-in modular input. Judging by the lack of responses I feel like that is not really the case...

0 Karma

grijhwani
Motivator

Not really a Splunk question. Wouldn't you reach a more informed audience on a more Windows-specific support forum?

That said, I just did a Google search for "powershell sockets", and amongst the first hits was this: Scripting Network / TCP Connections in PowerShell

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!

Take Action Automatically on Splunk Alerts with Red Hat Ansible Automation Platform

 Are you ready to revolutionize your IT operations? As digital transformation accelerates, the demand for ...

Calling All Security Pros: Ready to Race Through Boston?

Hey Splunkers, .conf25 is heading to Boston and we’re kicking things off with something bold, competitive, and ...

Beyond Detection: How Splunk and Cisco Integrated Security Platforms Transform ...

Financial services organizations face an impossible equation: maintain 99.9% uptime for mission-critical ...