PoshCode Archive  Artifact [2d07ba01c7]

Artifact 2d07ba01c75cda9af6be8d280973a913e45f2f3398d0b2b2438d5ec5b8ce6a8d:

  • File WhoIs.ps1 — part of check-in [b37cd54b2d] at 2018-06-10 13:24:44 on branch trunk — Whois Lookup information returning an OBJECT!!! save as Whois.ps1 and run at your leisure (user: CrazyDave size: 1373)

# encoding: ascii
# api: powershell
# title: WhoIs
# description: Whois Lookup information returning an OBJECT!!! save as Whois.ps1 and run at your leisure
# version: 0.1
# author: CrazyDave
# license: CC0
# x-poshcode-id: 3384
# x-archived: 2016-07-13T08:55:17
# x-published: 2012-04-24T21:23:00
#
#
param([String] $DomainName = '192.168.0.1')
$socket = New-Object System.Net.Sockets.Socket ([System.Net.Sockets.AddressFamily]::InterNetwork, [System.Net.Sockets.SocketType]::Stream, [System.Net.Sockets.ProtocolType]::Tcp)

$Socket.Connect('whois.arin.net', 43) | out-null
$bytes = [System.Text.Encoding]::ASCII.GetBytes($domainName + "`n")
$Socket.Send($bytes) | out-null
$bytes = [Array]::CreateInstance("byte", 2048)
$Socket.Receive($bytes) | out-null
$result = [System.Text.Encoding]::ASCII.GetString($bytes).Trim()
$Socket.Close()

$Data = New-Object Object
$Data | Add-Member NoteProperty Raw ($result)
$result -split "`n" | % {
  if (![String]::IsNullOrEmpty($_)) {
    $num = $_.IndexOf(":")    
    if ($num -gt 0) {
      $itemName = $_.SubString(0,$num).Trim()
      $itemValue = $_.SubString($num+1).Trim()
      
      if (($Data | Get-Member $itemName)) {
        $Data.($itemName) += "|" + $itemValue
      }
      else {
        $Data | Add-Member NoteProperty ($itemName) ($itemValue)
      }
    }
  }
}

$Data