在LAN中获取IP和物理地址 [英] Get IP and Physical Address in LAN

查看:120
本文介绍了在LAN中获取IP和物理地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你介意我是否要求完整的源代码C#.NET 4关于在局域网中获取IP和物理地址。

解决方案

使用System;使用System.Collections.Generic;

使用System.ComponentModel;

使用System.Data;使用System.Drawing;

使用System.Text;

使用System.Windows.Forms;

使用System.Net;

使用System.Management;

使用System.Net.Sockets;使用System.Collections; //使用System.ComponentModel;使用System.Windows.Forms;使用System.Data;

名称空间测试{

公共部分类Form1:表格



{



public Form1()



{



InitializeComponent();



}



private void button1_Click(object sender,EventArgs e)



{



string s =,mac =;



string hostInfo = Dns.GetHostName();



System.Net.IPAddress [] addressList = Dns.GetHostByName(Dns.GetHostName())。AddressList;



for(int i = 0; i< addressList.Length; i ++)



{



s + = addressList [i] .ToString(); } ManagementClass mc;



mc = new ManagementClass(Win32_NetworkAdapterConfiguration); ManagementObjectCollection moc = mc.GetInstances();



foreach(管理对象在moc中)



{



if(mo [IPEnabled]。ToString()==True)



mac = mo [MacAddress]。ToString ();



this.textBox1.AppendText(mac +\ n \\\\\);



}



this.Text + = hostInfo;



this.Text + = s;



this.Text + = mac;



// button1.Enabled = false; button2.Focus();

}

}

}


是的,我们介意。我们不打算为你工作。


谢谢大家,我不会忘记义务。 (^ _ ^)

Do you mind if I request for complete source code C# .NET 4 about Get IP and Physical Address in LAN.

解决方案

using System; using System.Collections.Generic;
using System.ComponentModel;
using System.Data; using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Net;
using System.Management;
using System.Net.Sockets; using System.Collections; //using System.ComponentModel;using System.Windows.Forms;using System.Data;
namespace test {
public partial class Form1 : Form

{

public Form1()

{

InitializeComponent();

}

private void button1_Click(object sender, EventArgs e)

{

string s="",mac="";

string hostInfo = Dns.GetHostName();

System.Net.IPAddress[] addressList = Dns.GetHostByName(Dns.GetHostName()).AddressList;

for (int i = 0; i < addressList.Length; i ++)

{

s += addressList[i].ToString(); } 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();

this.textBox1.AppendText(mac + "\n\r\n\r");

}

this.Text+=hostInfo;

this.Text+=s;

this.Text+=mac;

// button1.Enabled=false; button2.Focus();
}
}
}


Yes, we mind. We're not going to do your work for you.


Thank you everybody, I not forget Obligation. (^_^)


这篇关于在LAN中获取IP和物理地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆