Click here to Skip to main content
15,896,502 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
C#
namespace HostNIPAddr
{

	public class MOSTRAR : System.Windows.Forms.Form
	{
		internal System.Windows.Forms.Button txtcerrar
		internal System.Windows.Forms.Button txtmostrar
		internal System.Windows.Forms.ListView ListaPcIp
		internal System.Windows.Forms.ColumnHeader NombrePc
		internal System.Windows.Forms.ColumnHeader DireccionIp
		internal System.Windows.Forms.StatusBar ESTADO;
		private System.Windows.Forms.TextBox TxtGrupoTrabajo
		private System.Windows.Forms.Label txtlabel1
		private System.Windows.Forms.ColumnHeader DireccionMac

		[DllImport("iphlpapi.dll", ExactSpelling=true)]
		public static extern int SendARP( int DestIP, int SrcIP, [Out] byte[] pMacAddr, ref int PhyAddrLen )


		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;

            Public MOSTRAR()
		{
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();

			//
			// TODO: Add any constructor code after InitializeComponent call
			//
		}

		
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if (components != null) 
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
            System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(MOSTRAR));
            this.txtcerrar = new System.Windows.Forms.Button();
            this.txtmostrar = new System.Windows.Forms.Button();
            this.ListaPcIp = new System.Windows.Forms.ListView();
            this.NombrePc = new System.Windows.Forms.ColumnHeader();
            this.DireccionIp = new System.Windows.Forms.ColumnHeader();
            this.DireccionMac = new System.Windows.Forms.ColumnHeader();
            this.ESTADO = new System.Windows.Forms.StatusBar();
            this.TxtGrupoTrabajo = new System.Windows.Forms.TextBox();
            this.txtlabel1 = new System.Windows.Forms.Label();
            this.SuspendLayout();
            // 
            // txtcerrar
            // 
            this.txtcerrar.Location = new System.Drawing.Point(361, 203);
            this.txtcerrar.Name = "txtcerrar";
            this.txtcerrar.Size = new System.Drawing.Size(84, 20);
            this.txtcerrar.TabIndex = 7;
            this.txtcerrar.Text = "Cerrar";
            this.txtcerrar.Click += new System.EventHandler(this.ButClose_Click);
            // 
            // txtmostrar
            // 
            this.txtmostrar.Location = new System.Drawing.Point(361, 183);
            this.txtmostrar.Name = "txtmostrar";
            this.txtmostrar.Size = new System.Drawing.Size(84, 20);
            this.txtmostrar.TabIndex = 6;
            this.txtmostrar.Text = "Mostrar";
            this.txtmostrar.Click += new System.EventHandler(this.ButDisplay_Click);
            // 
            // ListaPcIp
            // 
            this.ListaPcIp.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
            this.NombrePc,
            this.DireccionIp,
            this.DireccionMac});
            this.ListaPcIp.Location = new System.Drawing.Point(16, 7);
            this.ListaPcIp.Name = "ListaPcIp";
            this.ListaPcIp.Size = new System.Drawing.Size(304, 272);
            this.ListaPcIp.TabIndex = 5;
            this.ListaPcIp.UseCompatibleStateImageBehavior = false;
            this.ListaPcIp.View = System.Windows.Forms.View.Details;
            // 
            // NombrePc
            // 
            this.NombrePc.Text = "Nombre Pc";
            this.NombrePc.Width = 100;
            // 
            // DireccionIp
            // 
            this.DireccionIp.Text = "Direccion IP";
            this.DireccionIp.Width = 100;
            // 
            // DireccionMac
            // 
            this.DireccionMac.Text = "Direccion Mac";
            this.DireccionMac.Width = 125;
            // 
            // ESTADO
            // 
            this.ESTADO.Location = new System.Drawing.Point(0, 430);
            this.ESTADO.Name = "ESTADO";
            this.ESTADO.Size = new System.Drawing.Size(484, 32);
            this.ESTADO.TabIndex = 4;
            // 
            // TxtGrupoTrabajo
            // 
            this.TxtGrupoTrabajo.Location = new System.Drawing.Point(361, 111);
            this.TxtGrupoTrabajo.Name = "TxtGrupoTrabajo";
            this.TxtGrupoTrabajo.Size = new System.Drawing.Size(80, 20);
            this.TxtGrupoTrabajo.TabIndex = 8;
            this.TxtGrupoTrabajo.Text = "Inacap";
            // 
            // txtlabel1
            // 
            this.txtlabel1.AutoSize = true;
            this.txtlabel1.Location = new System.Drawing.Point(358, 86);
            this.txtlabel1.Name = "txtlabel1";
            this.txtlabel1.Size = new System.Drawing.Size(92, 13);
            this.txtlabel1.TabIndex = 9;
            this.txtlabel1.Text = "Grupo De Trabajo";
            // 
            // MOSTRAR
            // 
            this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
            this.ClientSize = new System.Drawing.Size(484, 462);
            this.Controls.Add(this.txtlabel1);
            this.Controls.Add(this.TxtGrupoTrabajo);
            this.Controls.Add(this.txtcerrar);
            this.Controls.Add(this.txtmostrar);
            this.Controls.Add(this.ListaPcIp);
            this.Controls.Add(this.ESTADO);
            this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
            this.MaximumSize = new System.Drawing.Size(500, 500);
            this.MinimumSize = new System.Drawing.Size(500, 500);
            this.Name = "MOSTRAR";
            this.Text = "PC CONECTADOS";
            this.Load += new System.EventHandler(this.MOSTRAR_Load);
            this.ResumeLayout(false);
            this.PerformLayout();

		}
		#endregion

		/// <summary>
		/// The main entry point for the application.
		/// </summary>
		[STAThread]
		static void Main() 
		{
			Application.Run(new MOSTRAR());
		}

		private void ButDisplay_Click(object sender, System.EventArgs e)
		{
			try
			{

				this.ESTADO.Text = "Collecting Information...";

				if(this.TxtGrupoTrabajo.Text.Trim() == "")
				{
					MessageBox.Show("The Work Group name Should Not be Empty");
					return;
				}


				// Use Your work Group WinNT://&&&&(Work Group Name)
				DirectoryEntry DomainEntry = new DirectoryEntry("WinNT://" + this.TxtGrupoTrabajo.Text.Trim());
				DomainEntry.Children.SchemaFilter.Add("computer");


				// To Get all the System names And Display with the Ip Address
				foreach(DirectoryEntry machine in DomainEntry.Children)
				{
					string[] Ipaddr = new string[3];
					Ipaddr[0] = machine.Name;

					System.Net.IPHostEntry Tempaddr = null;

					try
					{
						Tempaddr = (System.Net.IPHostEntry)Dns.GetHostByName(machine.Name);
					}
					catch(Exception ex)
					{
						MessageBox.Show("Unable to connect woth the system :" + machine.Name );
						continue;
					}
					System.Net.IPAddress[] TempAd = Tempaddr.AddressList;
					foreach(IPAddress TempA in TempAd)
					{
						Ipaddr[1] = TempA.ToString();

						byte[] ab = new byte[6];
						int len = ab.Length;

						// This Function Used to Get The Physical Address
						int r = SendARP( (int) TempA.Address, 0, ab, ref len );
						string mac = BitConverter.ToString( ab, 0, 6 );

						Ipaddr[2] = mac;
					}			

					System.Windows.Forms.ListViewItem TempItem = new ListViewItem(Ipaddr);

					this.ListaPcIp.Items.Add(TempItem);
				}

				this.ESTADO.Text = "CONECTADOS"
			}
			catch(Exception ex)
			{
				MessageBox.Show(ex.Message,"Error",System.Windows.Forms.MessageBoxButtons.OK  );
				Application.Exit();
			}

		}

		private void ButClose_Click(object sender, System.EventArgs e)
		{
			this.Close();
		}

        private void MOSTRAR_Load(object sender, EventArgs e)
        {

        }
	}
}
Posted
Updated 12-Aug-10 7:14am
v2
Comments
TheyCallMeMrJames 12-Aug-10 11:54am    
Reason for my vote of 1
no explanation, too much code, no real question.
Toli Cuturicu 12-Aug-10 13:13pm    
Reason for my vote of 1
No question
HimanshuJoshi 12-Aug-10 13:15pm    
Reason for my vote of 1
No question/explanation just code
OriginalGriff 12-Aug-10 14:24pm    
Edit your question to show just the relevant code, and to include what your problem actually is. I think you forgot to say...
sagredo_azul 12-Aug-10 14:36pm    
look, I explain what I want to do is show all the computers connected to the same wifi network, showing its name from the pc, your IP address and MAC address ..
and found that code .. I need it in vb.net but not in the code that ... hopefully you can help me ... to apologize if I write bad is that I use more or less in English .. please help

If I understand correctly, you want to convert this code to VB.NET.

See here:
http://www.developerfusion.com/tools/convert/csharp-to-vb/[^]

or here:
http://converter.telerik.com/[^]

If this isn't what you want, please explain you problem clearly.
 
Share this answer
 
Compile the C# code, toss the DLL into Reflector, then disassemble it with the language set to VB.Net.
 
Share this answer
 
You have provided a pile of code and asked no questions.


People will not trawl through that for no reason.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900