
08.03.2010, 01:39
|
|
Познавший АНТИЧАТ
Регистрация: 12.07.2008
Сообщений: 1,705
С нами:
9384806
Репутация:
1350
|
|
Еще один небольшой пример работы с PrimalForms, а именно получение IP по имени и на оборот имени по IP(так сказать минимальная возможность nslookup). Проверку на валидность IP ,здесь я взял regex с сайта http://www.regular-expressions.info/examples.html .
#Generated Form Function
function GenerateForm {
################################################## ######################
# Code Generated By: SAPIEN Technologies PrimalForms (Community Edition) v1.0.8.0
# Generated By: SpangeBoB
################################################## ######################
#region Import the Assemblies
[reflection.assembly]::loadwithpartialname("System.Windows.Forms") | Out-Null
[reflection.assembly]::loadwithpartialname("System.Drawing") | Out-Null
#endregion
#region Generated Form Objects
$form1 = New-Object System.Windows.Forms.Form
$label2 = New-Object System.Windows.Forms.Label
$label1 = New-Object System.Windows.Forms.Label
$button1 = New-Object System.Windows.Forms.Button
$richTextBox2 = New-Object System.Windows.Forms.RichTextBox
$richTextBox1 = New-Object System.Windows.Forms.RichTextBox
$InitialFormWindowState = New-Object System.Windows.Forms.FormWindowState
#endregion Generated Form Objects
#----------------------------------------------
#Generated Event Script Blocks
#----------------------------------------------
#Provide Custom Code for events specified in PrimalForms.
$button1_OnClick=
{
if (($name=$richTextBox1.Text))
{
try {
if ($name -match '\b(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b')
{
$ip=[System.Net.IPAddress]::Parse($name).IPAddressToString
$richTextBox2.Text = [System.Net.Dns]::GetHostByAddress($ip).HostName
}
else {
$ip = [System.Net.Dns]::GetHostAddresses($name) | ForEach-Object { $_.IPAddressToString}
$ofs = ","
$richTextBox2.Text = $ip
}
}
catch [System.Management.Automation.MethodInvocationExcep tion]
{
[System.Windows.Forms.MessageBox]::Show("Enter correct host!")
}
}
else { [System.Windows.Forms.MessageBox]::Show("Enter host!")}
}
$OnLoadForm_StateCorrection=
{#Correct the initial state of the form to prevent the .Net maximized form issue
$form1.WindowState = $InitialFormWindowState
}
#----------------------------------------------
#region Generated Form Code
$form1.Text = "Simple Resolve"
$form1.Name = "form1"
$form1.DataBindings.DefaultDataSourceUpdateMode = 0
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Width = 404
$System_Drawing_Size.Height = 129
$form1.ClientSize = $System_Drawing_Size
$label2.TabIndex = 4
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Width = 22
$System_Drawing_Size.Height = 24
$label2.Size = $System_Drawing_Size
$label2.Text = "IP"
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 28
$System_Drawing_Point.Y = 62
$label2.Location = $System_Drawing_Point
$label2.DataBindings.DefaultDataSourceUpdateMode = 0
$label2.Name = "label2"
$form1.Controls.Add($label2)
$label1.TabIndex = 3
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Width = 34
$System_Drawing_Size.Height = 21
$label1.Size = $System_Drawing_Size
$label1.Text = "Host"
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 28
$System_Drawing_Point.Y = 12
$label1.Location = $System_Drawing_Point
$label1.DataBindings.DefaultDataSourceUpdateMode = 0
$label1.Name = "label1"
$form1.Controls.Add($label1)
$button1.TabIndex = 2
$button1.Name = "button1"
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Width = 57
$System_Drawing_Size.Height = 27
$button1.Size = $System_Drawing_Size
$button1.UseVisualStyleBackColor = $True
$button1.Text = "Resolve"
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 324
$System_Drawing_Point.Y = 35
$button1.Location = $System_Drawing_Point
$button1.DataBindings.DefaultDataSourceUpdateMode = 0
$button1.add_Click($button1_OnClick)
$form1.Controls.Add($button1)
$richTextBox2.Name = "richTextBox2"
$richTextBox2.ScrollBars = 0
$richTextBox2.Text = ""
$richTextBox2.DataBindings.DefaultDataSourceUpdate Mode = 0
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 71
$System_Drawing_Point.Y = 62
$richTextBox2.Location = $System_Drawing_Point
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Width = 229
$System_Drawing_Size.Height = 36
$richTextBox2.Size = $System_Drawing_Size
$richTextBox2.TabIndex = 1
$form1.Controls.Add($richTextBox2)
$richTextBox1.Name = "richTextBox1"
$richTextBox1.MaxLength = 255
$richTextBox1.ScrollBars = 0
$richTextBox1.Text = ""
$richTextBox1.DataBindings.DefaultDataSourceUpdate Mode = 0
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 71
$System_Drawing_Point.Y = 12
$richTextBox1.Location = $System_Drawing_Point
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Width = 231
$System_Drawing_Size.Height = 22
$richTextBox1.Size = $System_Drawing_Size
$richTextBox1.TabIndex = 0
$form1.Controls.Add($richTextBox1)
#endregion Generated Form Code
#Save the initial state of the form
$InitialFormWindowState = $form1.WindowState
#Init the OnLoad event to correct the initial state of the form
$form1.add_Load($OnLoadForm_StateCorrection)
#Show the Form
$form1.ShowDialog()| Out-Null
} #End Function
#Call the Function
GenerateForm
|
|
|