PoshCode Archive  Artifact Content

Artifact b0958de6a6928a64e5b5566c4b79610b60fac8cc5493b95cd15964fc3175a64c:

  • File WhoIs.ps1 — part of check-in [d5a74f6fa9] at 2018-06-10 12:58:00 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: 1515
# x-archived: 2017-05-13T16:18:01
# x-published: 2010-12-08T12:14: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