Chapter 4. TCP port communications with PowerShell

 

Boe Prox

PowerShell can be a powerful network troubleshooting tool thanks to its reach back into the .NET framework. In this chapter I’ll take you through some of the more useful .NET classes that you can harness to help with your network troubleshooting and with building some fun scripts. By the end of the chapter you’ll know how to create a port scanner to check for open ports on your network, send and receive data between ports, create formatted packets to send a Lightweight Directory Access Protocol (LDAP) request to a domain controller, and process the return packets to emulate the same type of output from another command-line interface (CLI) tool, portqry.exe. You’ll also learn about creating a TCP listener object that will serve as an open port on your system to allow clients to connect to your system, and lastly, you’ll put everything together to create an Echo server that can repeat back to you every key that you’ve typed! By using these techniques and scripts you’ll be able to troubleshoot applications communicating on your network by checking to see if the ports required are available on the system or if they’re being blocked, either by software on the server or by something else, such as a hardware firewall or an access control list (ACL) on a switch.

Before I begin, let’s review some terminology.

Testing for an open port

Sending and receiving data

LDAP port communications

Creating an Echo server

Summary

About the author

sitemap