Monday, May 25, 2015

(Powershell) Zip / Unzip


Add-Type -AssemblyName System.IO.Compression.FileSystem
function Unzip
{
    param([string]$zipfile, [string]$outpath)

    [System.IO.Compression.ZipFile]::ExtractToDirectory($zipfile, $outpath)
}

Unzip "C:\a.zip" "C:\a"

Friday, May 15, 2015

(PowerShell) Quick and dirty NetCat style listener

I was trying to come up with something in PowerShell that would listen on an arbitrary port and return a string. This seems to do the job perfectly.


while ($true)
{
    $listener = new-object System.Net.Sockets.TcpListener([System.Net.IPAddress]::Parse('0.0.0.0'), 42000)

    $listener.start()

    $client = $listener.AcceptTcpClient()

    $stream = $client.GetStream()
   
    $stWriter = new-Object System.IO.StreamWriter($stream)
   
    $stWriter.WriteLine("Put your text right here")
    $stWriter.Flush
    $stWriter.Close()

    $client.Close()

    $listener.Stop()

    write-host "Connection closed."
}