There are a number of web sites that expose Web Services for public access. One of the better ones is WebserviceX.net, whom I have used to do a WhoIS lookup of domain registry information. The web services provided by WebserviceX.net are described by WSDL (Web Services Description Language) supporting SOAP (Simple Object Access Protocol) requests and returning XML (Extensible Markup Language).

In a simple WinForms form I gather the domain name in a TextBox.

Add-Type -AssemblyName System.Windows.Forms
# Main Form
$mainForm = New-Object System.Windows.Forms.Form
$mainForm.Font = "Comic Sans MS,10"
$mainForm.Text = " WhoIS Lookup"
$mainForm.ForeColor = "White"
$mainForm.BackColor = "Chocolate"
$mainForm.Width = 600
$mainForm.Height = 600

# Input TextBox
$inputTextBox = New-Object System.Windows.Forms.TextBox
$inputTextBox.Location = "45,8"
$inputTextBox.Size = "300,20"
$inputTextBox.ForeColor = "MediumBlue"
$inputTextBox.BackColor = "White"
$inputTextBox.Text = "Enter Domain Name"
$mainForm.Controls.Add($inputTextBox)

When you click the Lookup button the WhoISLookup function is called. In that function I setup a New-WebServiceProxy for the WebserviceX.net URL pointing to the WhoIS WSDL schema. To the webservice SOAP call, GetWhoIS, is passed the domain name. The returned value from the from the service provider for this call is the single string without the XML tags. I test for an error being returned and display the offending domain name if there is an error. Errors like this come from an improperly formatted domain name, like wordpress.vom. Unregistered names are returned as such from the registrar. The error counter is cleared each time at the start of the function.

# Lookup Button
$lookupButton = New-Object System.Windows.Forms.Button
$lookupButton.Location = "395,8"
$lookupButton.Size = "75,28"
$lookupButton.ForeColor = "DarkBlue"
$lookupButton.BackColor = "White"
$lookupButton.Text = "Lookup"
$lookupButton.add_Click({WhoISLookup})
$mainForm.Controls.Add($lookupButton)

Function WhoISLookup {
    $error.clear()
    $WhoIS = New-WebServiceProxy -uri "http://www.webservicex.net/whois.asmx?WSDL"
    $WhoISResults = $WhoIS.GetWhoIS($inputTextBox.Text)
    If($error.count -gt 0) {
        $outputTextBox.Text = "Bad Lookup of '" + $inputTextBox.Text + "'"
    }
    Else {
        $outputTextBox.Text = $WhoISResults
    }
}

I display the returned string in a RichTextBox so it is properly formatted and takes advantage of the Multiline, Wordwrap and Scrollbar properties.

# OutputTextBox
$outputTextBox = New-Object System.Windows.Forms.RichTextBox
$outputTextBox.Location = "45,45"
$outputTextBox.Size = "500,490"
$outputTextBox.ForeColor = "MediumBlue"
$outputTextBox.BackColor = "White"
$outputTextBox.Multiline = $true
$outputTextBox.Scrollbars = "Vertical"
$outputTextBox.Wordwrap = $true
$mainForm.Controls.Add($outputTextBox)

The service call can take anywhere from a second to six or seven seconds, depending on the service provider response.

WhoIS

WhoIS.ps1

Advertisements