Quantcast
Channel: /r/powershell – How to Code .NET
Viewing all articles
Browse latest Browse all 8793

Having trouble with TCPClient and receiving data.

$
0
0

I am trying to write some scripts that connect to our Nagios server and retreives some information, such as which servers are in downtime and the comments on the downtimes.

Nagios uses a language called LQL or “Livestatus Query Language” This is not something I am having a problem with at the moment. but I am having issues with getting data from the server, I can set up a TCPClient and send data fine, but when I try read from the stream it gets no data…

Here is my code so far with ip and port omitted. PasteBin Link

$Socket = New-Object System.Net.Sockets.TCPClient($ip,$port) $stream = $Socket.GetStream() $enc = [system.Text.Encoding]::UTF8 $string1 = "echo 'GET Host' " $data1 = $enc.GetBytes($string1) $stream.Write($data1,0,$data1.Length) # $stream.close(20) $byte = New-Object Byte[] 256 $stream.read($byte,0,$byte.Length) 

Any help would be much appreciated!

submitted by /u/TheSilenceOfWinter
[link] [comments]

The post Having trouble with TCPClient and receiving data. appeared first on How to Code .NET.


Viewing all articles
Browse latest Browse all 8793

Latest Images

Trending Articles



Latest Images