Not really used anymore but was used for pinholing DNS for Zscaler
This commit is contained in:
98
haystack.ps1
Normal file
98
haystack.ps1
Normal file
@@ -0,0 +1,98 @@
|
||||
##############################################################
|
||||
## Change Log #
|
||||
## 1.0 Initial release #
|
||||
## 1.1 Added logic for resolved IP to be displayed on screen.#
|
||||
##############################################################
|
||||
|
||||
|
||||
Add-Type -AssemblyName System.Windows.Forms
|
||||
Add-Type -AssemblyName System.Drawing
|
||||
|
||||
# Create form controls
|
||||
$form = New-Object System.Windows.Forms.Form
|
||||
$form.Text = "Haystack"
|
||||
$form.ClientSize = New-Object System.Drawing.Size(400, 270)
|
||||
|
||||
# Create a PictureBox control
|
||||
$pictureBox = New-Object System.Windows.Forms.PictureBox
|
||||
$pictureBox.Location = New-Object System.Drawing.Point(160, 120)
|
||||
$pictureBox.Size = New-Object System.Drawing.Size(200, 200)
|
||||
$image = [System.Drawing.Image]::FromFile("\\win1215\C$\TEMP\Source\Server Built Apps\Datacom-SOE\Checks\MandatoryChecks\JJ.png")
|
||||
$pictureBox.Image = $image
|
||||
|
||||
$dnsNameLabel = New-Object System.Windows.Forms.Label
|
||||
$dnsNameLabel.Text = "A Record:"
|
||||
$dnsNameLabel.Location = New-Object System.Drawing.Point(10, 20)
|
||||
$dnsNameLabel.AutoSize = $true
|
||||
|
||||
$dnsNameTextbox = New-Object System.Windows.Forms.TextBox
|
||||
$dnsNameTextbox.Location = New-Object System.Drawing.Point(120, 20)
|
||||
$dnsNameTextbox.Size = New-Object System.Drawing.Size(250, 20)
|
||||
|
||||
$zoneLabel = New-Object System.Windows.Forms.Label
|
||||
$zoneLabel.Text = "DNS Zone:"
|
||||
$zoneLabel.Location = New-Object System.Drawing.Point(10, 50)
|
||||
$zoneLabel.AutoSize = $true
|
||||
|
||||
$zoneTextbox = New-Object System.Windows.Forms.TextBox
|
||||
$zoneTextbox.Location = New-Object System.Drawing.Point(120, 50)
|
||||
$zoneTextbox.Size = New-Object System.Drawing.Size(250, 20)
|
||||
|
||||
$ipLabel = New-Object System.Windows.Forms.Label
|
||||
$ipLabel.Text = "IP Address:"
|
||||
$ipLabel.Location = New-Object System.Drawing.Point(10, 80)
|
||||
$ipLabel.Size = New-Object System.Drawing.Size(62, 10)
|
||||
$form.Controls.Add($ipLabel)
|
||||
|
||||
$ipTextBox = New-Object System.Windows.Forms.TextBox
|
||||
$ipTextBox.Location = New-Object System.Drawing.Point(10, 100)
|
||||
$ipTextBox.ReadOnly = $true
|
||||
$form.Controls.Add($ipTextBox)
|
||||
|
||||
$createButton = New-Object System.Windows.Forms.Button
|
||||
$createButton.Location = New-Object System.Drawing.Point(120, 80)
|
||||
$createButton.Size = New-Object System.Drawing.Size(150, 23)
|
||||
$createButton.Text = "Create Zone and A Record"
|
||||
$createButton.Add_Click({
|
||||
# Combine fields and ping DNS name
|
||||
$combined = $dnsNameTextbox.Text + "." + $zoneTextbox.Text
|
||||
$pingResult = Test-Connection -ComputerName $combined -Count 1 -Quiet
|
||||
|
||||
# Get IP address using Resolve-DnsName
|
||||
$ipAddress = ""
|
||||
$dnsResult = Resolve-DnsName -Name $combined -Type A -ErrorAction SilentlyContinue
|
||||
if ($dnsResult) {
|
||||
$ipAddress = $dnsResult.IPAddress
|
||||
}
|
||||
|
||||
# If ping failed and Resolve-DnsName didn't return an IP address, show error message and exit
|
||||
if (!$pingResult -and !$dnsResult) {
|
||||
[System.Windows.Forms.MessageBox]::Show("Could not resolve DNS name.")
|
||||
return
|
||||
}
|
||||
|
||||
# Create DNS zone and A record
|
||||
$zoneName = $zoneTextbox.Text
|
||||
$aRecord = $dnsNameTextbox.Text
|
||||
if ($ipAddress) {
|
||||
$aRecord = $ipAddress
|
||||
}
|
||||
Add-DnsServerPrimaryZone -Name $combined -ZoneFile $zoneName
|
||||
Add-DnsServerResourceRecordA -Name $combined -ZoneName $combined -IPv4Address $aRecord
|
||||
[System.Windows.Forms.MessageBox]::Show("DNS zone and A record created successfully.")
|
||||
})
|
||||
|
||||
$ipTextBox.Text = $ipAddress
|
||||
|
||||
# Add controls to form
|
||||
$form.Controls.Add($dnsNameLabel)
|
||||
$form.Controls.Add($dnsNameTextbox)
|
||||
$form.Controls.Add($zoneLabel)
|
||||
$form.Controls.Add($zoneTextbox)
|
||||
$form.Controls.Add($createButton)
|
||||
$form.Controls.Add($pictureBox)
|
||||
$form.Controls.Add($ipLabel)
|
||||
$form.Controls.Add($ipTextBox)
|
||||
|
||||
# Show the form
|
||||
$form.ShowDialog() | Out-Null
|
||||
Reference in New Issue
Block a user