Using System;
Using System. Drawing;
Using System. Management;
Using System. Net;
Using System. Net. Sockets;
Using System. Collections;
Using System. ComponentModel;
Using System. Windows. Forms;
Using System. Data;
Namespace MAC_IP_name
{
/// <Summary>
/// Summary of Form1.
/// </Summary>
Public class Form1: System. Windows. Forms. Form
{
Private System. Windows. Forms. Label label4;
Private System. Windows. Forms. GroupBox groupBox1;
Private System. Windows. Forms. TextBox txtMac;
Private System. Windows. Forms. TextBox txtIp;
Private System. Windows. Forms. TextBox txtName;
Private System. Windows. Forms. Label lblMac;
Private System. Windows. Forms. Label lblIp;
Private System. Windows. Forms. Label lblName;
Private System. Windows. Forms. Button button1;
Private System. Windows. Forms. Button button2;
/// <Summary>
/// Required designer variables.
/// </Summary>
Private System. ComponentModel. Container components = null;
Public Form1 ()
{
//
// Required for Windows Form Designer support
//
InitializeComponent ();
//
// TODO: add Any constructor code after InitializeComponent calls
//
}
/// <Summary>
/// Clear all resources in use.
/// </Summary>
Protected override void Dispose (bool disposing)
{
If (disposing)
{
If (components! = Null)
{
Components. Dispose ();
}
}
Base. Dispose (disposing );
}
# Region code generated by Windows Form Designer
/// <Summary>
/// The designer supports the required methods-do not use the code editor to modify
/// Content of this method.
/// </Summary>
Private void InitializeComponent ()
{
This. label4 = new System. Windows. Forms. Label ();
This. groupBox1 = new System. Windows. Forms. GroupBox ();
This. button2 = new System. Windows. Forms. Button ();
This.txt Mac = new System. Windows. Forms. TextBox ();
This.txt Ip = new System. Windows. Forms. TextBox ();
This.txt Name = new System. Windows. Forms. TextBox ();
This. lblMac = new System. Windows. Forms. Label ();
This. lblIp = new System. Windows. Forms. Label ();
This. lblName = new System. Windows. Forms. Label ();
This. button1 = new System. Windows. Forms. Button ();
This. groupBox1.SuspendLayout ();
This. SuspendLayout ();
//
// Label4
//
This. label4.AutoSize = true;
This. label4.Font = new System. drawing. font (" _ GB2312", 15F, System. drawing. fontStyle. bold, System. drawing. graphicsUnit. point, (System. byte) (134 )));
This. label4.ForeColor = System. drawing. color. fromArgb (System. byte) (255), (System. byte) (128), (System. byte) (128 )));
This. label4.Location = new System. Drawing. Point (49, 16 );
This. label4.Name = "label4 ";
This. label4.Size = new System. Drawing. Size (245, 26 );
This. label4.TabIndex = 7;
This. label4.Text = "get the IP address and MAC address of the Local Computer ";
//
// GroupBox1
//
This. groupBox1.Controls. Add (this. button2 );
This.groupBox1.Controls.Add(this.txt Mac );
This.groupBox1.Controls.Add(this.txt Ip );
This.groupBox1.Controls.Add(this.txt Name );
This. groupBox1.Controls. Add (this. lblMac );
This. groupBox1.Controls. Add (this. lblIp );
This. groupBox1.Controls. Add (this. lblName );
This. groupBox1.Controls. Add (this. button1 );
This. groupBox1.Location = new System. Drawing. Point (16, 56 );
This. groupBox1.Name = "groupBox1 ";
This. groupBox1.Size = new System. Drawing. Size (320,208 );
This. groupBox1.TabIndex = 11;
This. groupBox1.TabStop = false;
This. groupBox1.Text = "Get zone ";
//
// Button2
//
This. button2.Font = new System. drawing. font ("", 9F, System. drawing. fontStyle. bold, System. drawing. graphicsUnit. point, (System. byte) (134 )));
This. button2.Location = new System. Drawing. Point (184,160 );
This. button2.Name = "button2 ";
This. button2.Size = new System. Drawing. Size (88, 32 );
This. button2.TabIndex = 18;
This. button2.Text = "quit ";
This. button2.Click + = new System. EventHandler (this. button2_Click );
//
// TxtMac
//
This.txt Mac. backColor = System. drawing. color. fromArgb (System. byte) (224), (System. byte) (224), (System. byte) (224 )));
This.txt Mac. font = new System. drawing. font ("", 9F, System. drawing. fontStyle. bold, System. drawing. graphicsUnit. point, (System. byte) (134 )));
This.txt Mac. foreColor = System. drawing. color. fromArgb (System. byte) (255), (System. byte) (128), (System. byte) (0 )));
This.txt Mac. Location = new System. Drawing. Point (128,110 );
This.txt Mac. Name = "txtMac ";
This.txt Mac. ReadOnly = true;
This.txt Mac. Size = new System. Drawing. Size (168, 21 );
This.txt Mac. TabIndex = 17;
This.txt Mac. Text = "";
//
// TxtIp
//
This.txt Ip. backColor = System. drawing. color. fromArgb (System. byte) (224), (System. byte) (224), (System. byte) (224 )));
This.txt Ip. font = new System. drawing. font ("", 9F, System. drawing. fontStyle. bold, System. drawing. graphicsUnit. point, (System. byte) (134 )));
This.txt Ip. foreColor = System. drawing. color. fromArgb (System. byte) (255), (System. byte) (128), (System. byte) (0 )));
This.txt Ip. Location = new System. Drawing. Point (128, 70 );
This.txt Ip. Name = "txtIp ";
This.txt Ip. ReadOnly = true;
This.txt Ip. Size = new System. Drawing. Size (168, 21 );
This.txt Ip. TabIndex = 16;
This.txt Ip. Text = "";
//
// TxtName
//
This.txt Name. backColor = System. drawing. color. fromArgb (System. byte) (224), (System. byte) (224), (System. byte) (224 )));
This.txt Name. font = new System. drawing. font ("", 9F, System. drawing. fontStyle. bold, System. drawing. graphicsUnit. point, (System. byte) (134 )));
This.txt Name. foreColor = System. drawing. color. fromArgb (System. byte) (255), (System. byte) (128), (System. byte) (0 )));
This.txt Name. Location = new System. Drawing. Point (128, 30 );
This.txt Name. Name = "txtName ";
This.txt Name. ReadOnly = true;
This.txt Name. Size = new System. Drawing. Size (168, 21 );
This.txt Name. TabIndex = 15;
This.txt Name. Text = "";
//
// LblMac
//
This. lblMac. AutoSize = true;
This. lblMac. font = new System. drawing. font ("", 12F, System. drawing. fontStyle. bold, System. drawing. graphicsUnit. point, (System. byte) (134 )));
This. lblMac. foreColor = System. drawing. color. fromArgb (System. byte) (0), (System. byte) (0), (System. byte) (64 )));
This. lblMac. Location = new System. Drawing. Point (32,112 );
This. lblMac. Name = "lblMac ";
This. lblMac. Size = new System. Drawing. Size (88, 22 );
This. lblMac. TabIndex = 14;
This. lblMac. Text = "MAC address :";
//
// LblIp
//
This. lblIp. AutoSize = true;
This. lblIp. font = new System. drawing. font ("", 12F, System. drawing. fontStyle. bold, System. drawing. graphicsUnit. point, (System. byte) (134 )));
This. lblIp. foreColor = System. drawing. color. fromArgb (System. byte) (0), (System. byte) (0), (System. byte) (64 )));
This. lblIp. Location = new System. Drawing. Point (40, 72 );
This. lblIp. Name = "lblIp ";
This. lblIp. Size = new System. Drawing. Size (80, 22 );
This. lblIp. TabIndex = 13;
This. lblIp. Text = "IP Address :";
//
// LblName
//
This. lblName. AutoSize = true;
This. lblName. font = new System. drawing. font ("", 12F, System. drawing. fontStyle. bold, System. drawing. graphicsUnit. point, (System. byte) (134 )));
This. lblName. foreColor = System. drawing. color. fromArgb (System. byte) (0), (System. byte) (0), (System. byte) (64 )));
This. lblName. Location = new System. Drawing. Point (24, 32 );
This. lblName. Name = "lblName ";
This. lblName. Size = new System. Drawing. Size (97, 22 );
This. lblName. TabIndex = 12;
This. lblName. Text = "computer name :";
//
// Button1
//
This. button1.Font = new System. drawing. font ("", 9F, System. drawing. fontStyle. bold, System. drawing. graphicsUnit. point, (System. byte) (134 )));
This. button1.Location = new System. Drawing. Point (48,160 );
This. button1.Name = "button1 ";
This. button1.Size = new System. Drawing. Size (88, 32 );
This. button1.TabIndex = 11;
This. button1.Text = "click to get ";
This. button1.Click + = new System. EventHandler (this. button#click_1 );
//
// Form1
//
This. AutoScaleBaseSize = new System. Drawing. Size (6, 14 );
This. ClientSize = new System. Drawing. Size (352,285 );
This. Controls. Add (this. groupBox1 );
This. Controls. Add (this. label4 );
This. FormBorderStyle = System. Windows. Forms. FormBorderStyle. Fixed3D;
This. MaximizeBox = false;
This. Name = "Form1 ";
This. StartPosition = System. Windows. Forms. FormStartPosition. CenterScreen;
This. Text = "IP, computer name, MAC query ";
This. groupBox1.ResumeLayout (false );
This. ResumeLayout (false );
}
# Endregion
/// <Summary>
/// Main entry point of the application.
/// </Summary>
[STAThread]
Static void Main ()
{
Application. Run (new Form1 ());
}
Private void button1_Click_1 (object sender, System. EventArgs e)
{
String s = "", mac = "";
//
// Name
//
String hostInfo = Dns. GetHostName ();
//
// IP
System. Net. IPAddress [] addressList = Dns. GetHostByName (Dns. GetHostName (). AddressList;
For (int I = 0; I <addressList. Length; I ++)
{
S + = addressList [I]. ToString ();
}
//
// Mac
//
ManagementClass mc;
Mc = new ManagementClass ("Win32_NetworkAdapterConfiguration ");
ManagementObjectCollection moc = mc. GetInstances ();
Foreach (ManagementObject mo in moc)
{
If (mo ["IPEnabled"]. ToString () = "True ")
Mac = mo ["MacAddress"]. ToString ();
}
TxtName. Text = hostInfo;
TxtIp. Text = s;
TxtMac. Text = mac;
Button1.Enabled = false;
Button2.Focus ();
}
Private void button2_Click (object sender, System. EventArgs e)
{
Application. Exit ();
}
}
}