NetShell

It’s been a while since I’ve posted, and since it’s almost Christmas I thought I’d better get on with it.

Without further ado I want to post NetShell (I’m not very good at coming up with imaginative names). NetShell is a collection of 17 functions and a few supporting functions in a script module.

The functions described here have been updated since posting this article. The updated functions are available as part of the script module Indented.NetworkTools.

Installation is a manual process, but not too hard. Open up DocumentsWindowsPowerShellModules, extract the ZIP file. Make sure it includes the NetShell folder or it won’t work. The module is not currently signed, something else on the to-do list. Once it’s there, Import-Module NetShell and off you go.

It includes the following:

**ConvertTo-BinaryIP**Converts an IP address into a binary string
**ConvertTo-Byte**A supporting function, a simple conversion of a string to a byte array (ASCII encoding)
**ConvertTo-DecimalIP**Converts an IP address to 32-bit decimal number
**ConvertTo-DottedDecimalIP**Converts a binary or 32-bit decimal back to an IP
**ConvertTo-Mask**Converts from a mask length. For example, gets you from 22 to 255.255.252.0
**ConvertTo-MaskLength**Converts from the IP form of a mask to the length
**ConvertTo-String**Another supporting function, converts a byte array to a string (ASCII encoding)
**Get-BroadcastAddress**Returns the broadcast address for the specified IP address and subnet mask
**Get-NetworkAddress**Returns the network address for the specified IP address and subnet mask
**Get-NetworkRange**Returns every IP within the specified range
**Get-NetworkSummary**Everything about an IP address and mask I considered useful
**New-DhcpDiscoverPacket**A supporting function for Send-DhcpDiscover. Creates the packet to send (a large byte array)
**New-Socket**Creates an instance of System.Net.Sockets.Socket, an arbitrary network socket to do with as you please.
**New-SysLogDateTime**A supporting function to create a DateTime string in the format SysLog likes.
**Read-DhcpOption**A supporting function to read off an Option from a DHCP packet. Needs to be fed the Extended.BinaryReader class at the top of the module.
**Read-DhcpPacket**Creates and uses an instance of Extended.BinaryReader to process a DHCP packet and translate the fields.
**Receive-Bytes**Receives a stream of bytes from the network using a socket
**Remove-Socket**Cleans up after New-Socket
**Send-Bytes**Sends an arbitrary byte array over the network using a socket
**Send-DhcpDiscover**Creates and sends a DHCPDISCOVER packet, then processes and returns the response
**Start-Syslog**Starts a SysLog server. No termination for this one at the moment. Needs a bit more work.
**Test-Smtp**Does the SMTP test you normally wind up doing with telnet, returning all the results along with the SMTP banner.
**Test-SysLogDateTime**A supporting function to check the format of a DateTime that may or may not be present in a SysLog message.
**Test-SysLogPRI**A supporting function to test of the PRI value in a SysLog message.
**Test-TcpPort**Returns a boolean indicating whether or not the port connection succeeded.
NetShell
Share this