Retrieving Hardware Identifiers in C# with WMI
http://eggheadcafe.com/articles/20030511.asphttp://www.codeguru.com/mfc/comments/49119.shtml

解决方案 »

  1.   

    MAC地址
    http://expert.csdn.net/Expert/topic/1662/1662992.xml?temp=.5716669
      

  2.   

    读取计算机的拨号上网临时的IP地址和局域网分配的固定IP地址:
    在程序设计中,我们是通过一个自定义的函数--getIPAddress ( )来读取IP地址的。首先看一下如何读取本地固定的IP地址的。在Dns类中还定义了一个方法GetHostByName( )。此方法的返回值时IPHostEntry 对象,此对象有一个属性是AddressList,此属性是一个IPAddress类型的数组,包含了计算机此时的所有的IP地址信息。这当中也就包含了拨号上网得到的临时分配的IP地址和局域网固定的IP地址。具体实现语句如下:
    private static stringgetIPAddress ( )
    {
    System.Net.IPAddress addr;
    // 获得本机局域网IP地址
    addr = new System.Net.IPAddress ( Dns.GetHostByName (Dns.GetHostName ( ) ) .AddressList [0].Address ) ;
    return addr.ToString ( ) ;
    }
    源程序如下:
    using System;
    using System.Drawing;
    using System.Collections;
    using System.ComponentModel;
    using System.Windows.Forms;
    using System.Data;
    using System.Net;namespace GetIP
    {
     public class Form1 : System.Windows.Forms.Form
     {
      private System.Windows.Forms.Label label1;
      private System.Windows.Forms.Label label2;
      private System.ComponentModel.Container components = null;
      public Form1()
      {   
       InitializeComponent();
       label1.Text=System.Net.Dns.GetHostName();
       label2.Text=getIpAddress();
      }
      protected override void Dispose( bool disposing )
      {
       if( disposing )
       {
        if (components != null) 
        {
         components.Dispose();
        }
       }
       base.Dispose( disposing );
      }
      #region Windows Form Designer generated code
      private void InitializeComponent()
      {
       this.label1 = new System.Windows.Forms.Label();
       this.label2 = new System.Windows.Forms.Label();
       this.SuspendLayout();   this.label1.Location = new System.Drawing.Point(48, 24);
       this.label1.Name = "label1";
       this.label1.Size = new System.Drawing.Size(264, 24);
       this.label1.TabIndex = 0;
       this.label1.Text = "label1";   this.label2.Location = new System.Drawing.Point(48, 64);
       this.label2.Name = "label2";
       this.label2.Size = new System.Drawing.Size(264, 24);
       this.label2.TabIndex = 1;
       this.label2.Text = "label2";   this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
       this.ClientSize = new System.Drawing.Size(376, 221);
       this.Controls.AddRange(new System.Windows.Forms.Control[] {this.label2,this.label1});
       this.Name = "Form1";
       this.Text = "Form1";
       this.ResumeLayout(false);
      }
      #endregion
      static void Main() 
      {
       Application.Run(new Form1());
      }
      private static string getIpAddress() 
      {
       System.Net.IPAddress addr;
       addr=new System.Net.IPAddress(Dns.GetHostByName(Dns.GetHostName()).AddressList[0].Address) ;
       return addr.ToString();
      }
     }
    }
      

  3.   

    第一个问题我不知道,对于第二个问题,其实可以这样做
     在cmd中输入ipconfig就可以查到本机的ip了.你可以在c#中调用这个exe文件就可以了
     也就6-7行程序的问题