<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Der Informatikblog &#187; C#</title>
	<atom:link href="http://www.informatik-blog.net/category/c/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.informatik-blog.net</link>
	<description>Informatik &#38; Co.</description>
	<lastBuildDate>Mon, 28 Jun 2010 19:43:30 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Mac Adresse rausfinden in C#</title>
		<link>http://www.informatik-blog.net/2009/08/25/mac-adresse-rausfinden-in-c/</link>
		<comments>http://www.informatik-blog.net/2009/08/25/mac-adresse-rausfinden-in-c/#comments</comments>
		<pubDate>Tue, 25 Aug 2009 09:33:12 +0000</pubDate>
		<dc:creator>Emanuel</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[GUI]]></category>
		<category><![CDATA[MAC-Adresse]]></category>
		<category><![CDATA[Visual Studio]]></category>

		<guid isPermaLink="false">http://www.informatik-blog.net/?p=598</guid>
		<description><![CDATA[

Wie bereits im Java Forum gepostet zeig ich euch auch noch wie ihr in C# die Mac-Adresse rausfindet.
Beachtet, dass ihr hierfür die Library  benötigt.
Hier stelle ich euch ein kleines tool mit GUI vor welches ich entwickelt habe um die Mac-Adresse auszulesen:

DefaultGUI.cs

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Management;
using System.Collections;

namespace MacGrabber
{
 public partial class [...]]]></description>
			<content:encoded><![CDATA[
<!-- google_ad_section_start -->
<p>Wie bereits im Java Forum gepostet zeig ich euch auch noch wie ihr in C# die Mac-Adresse rausfindet.</p>
<p>Beachtet, dass ihr hierfür die Library <system .Management.dll> benötigt.</p>
<p>Hier stelle ich euch ein kleines tool mit GUI vor welches ich entwickelt habe um die Mac-Adresse auszulesen:<br />
<span id="more-598"></span><br />
DefaultGUI.cs</p>
<pre class="brush: plain;">
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Management;
using System.Collections;

namespace MacGrabber
{
 public partial class DefaultGUI : Form
 {
 public DefaultGUI()
 {
 InitializeComponent();
 getNetworkData();
 }

 List&lt;NetworkItem&gt; NetworkData = new List&lt;NetworkItem&gt;();

 private void getNetworkData()
 {

 int i = 0;
 try
 {
 ManagementObjectSearcher query = new ManagementObjectSearcher(&quot;SELECT * FROM Win32_NetworkAdapterConfiguration&quot;);
 ManagementObjectCollection queryCollection = query.Get();
 foreach (ManagementObject mo in queryCollection)
 {

 if (mo[&quot;MacAddress&quot;] != null &amp;&amp; mo[&quot;IPAddress&quot;] != null)
 {
 NetworkData.Add(new NetworkItem(i, mo[&quot;Description&quot;].ToString(), mo[&quot;MacAddress&quot;].ToString().Replace(&quot;:&quot;, &quot;&quot;)));
 }
 }
 }
 catch (Exception ex)
 {
 Console.WriteLine(ex.Source);
 Console.WriteLine(ex.Message);
 }

 foreach (NetworkItem item in NetworkData)
 comboBoxMacList.Items.Add(item);
 if (this.comboBoxMacList.Items.Count &gt; 0)
 this.comboBoxMacList.SelectedIndex = 0;

 }
 private void label1_Click(object sender, EventArgs e)
 {

 }

 private void Form1_Load(object sender, EventArgs e)
 {

 }

 private void textBoxMacField_TextChanged(object sender, EventArgs e)
 {

 }

 private void setClipboard(string cbtext)
 {
 Clipboard.SetText(cbtext);
 }

 private void comboBoxMacList_SelectedIndexChanged(object sender, EventArgs e)
 {

 NetworkItem selectedItem = (sender as ComboBox).SelectedItem as NetworkItem;
 if (selectedItem != null)
 {
 settextBoxMacField(selectedItem.getMacAddr());
 setClipboard(selectedItem.getMacAddr());
 }
 }
 }
}
</pre>
<p>DefaultGUIDesigner.cs</p>
<pre class="brush: plain;">
namespace MacGrabber
{
 partial class DefaultGUI
 {
 /// &lt;summary&gt;
 /// Required designer variable.
 /// &lt;/summary&gt;
 private System.ComponentModel.IContainer components = null;

 /// &lt;summary&gt;
 /// Clean up any resources being used.
 /// &lt;/summary&gt;
 /// &lt;param name=&quot;disposing&quot;&gt;true if managed resources should be disposed; otherwise, false.&lt;/param&gt;
 protected override void Dispose(bool disposing)
 {
 if (disposing &amp;&amp; (components != null))
 {
 components.Dispose();
 }
 base.Dispose(disposing);
 }

 #region Windows Form Designer generated code

 /// &lt;summary&gt;
 /// Required method for Designer support - do not modify
 /// the contents of this method with the code editor.
 /// &lt;/summary&gt;
 private void InitializeComponent()
 {
 System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(DefaultGUI));
 this.labelMac = new System.Windows.Forms.Label();
 this.textBoxMacField = new System.Windows.Forms.TextBox();
 this.comboBoxMacList = new System.Windows.Forms.ComboBox();
 this.SuspendLayout();
 //
 // labelMac
 //
 this.labelMac.AutoSize = true;
 this.labelMac.Location = new System.Drawing.Point(13, 7);
 this.labelMac.Name = &quot;labelMac&quot;;
 this.labelMac.Size = new System.Drawing.Size(72, 13);
 this.labelMac.TabIndex = 0;
 this.labelMac.Text = &quot;Mac-Adresse:&quot;;
 this.labelMac.Click += new System.EventHandler(this.label1_Click);
 //
 // textBoxMacField
 //
 this.textBoxMacField.Location = new System.Drawing.Point(90, 4);
 this.textBoxMacField.Name = &quot;textBoxMacField&quot;;
 this.textBoxMacField.Size = new System.Drawing.Size(208, 20);
 this.textBoxMacField.TabIndex = 1;
 this.textBoxMacField.TextChanged += new System.EventHandler(this.textBoxMacField_TextChanged);
 //
 // comboBoxMacList
 //
 this.comboBoxMacList.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
 this.comboBoxMacList.Location = new System.Drawing.Point(16, 30);
 this.comboBoxMacList.Name = &quot;comboBoxMacList&quot;;
 this.comboBoxMacList.Size = new System.Drawing.Size(282, 21);
 this.comboBoxMacList.TabIndex = 2;
 this.comboBoxMacList.SelectedIndexChanged += new System.EventHandler(this.comboBoxMacList_SelectedIndexChanged);
 //
 // DefaultGUI
 //
 this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
 this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
 this.ClientSize = new System.Drawing.Size(310, 58);
 this.Controls.Add(this.comboBoxMacList);
 this.Controls.Add(this.textBoxMacField);
 this.Controls.Add(this.labelMac);
 this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
 this.Icon = ((System.Drawing.Icon)(resources.GetObject(&quot;$this.Icon&quot;)));
 this.Name = &quot;DefaultGUI&quot;;
 this.Text = &quot;Mac Grabber&quot;;
 this.Load += new System.EventHandler(this.Form1_Load);
 this.ResumeLayout(false);
 this.PerformLayout();

 }

 #endregion

 private void settextBoxMacField(string text) { this.textBoxMacField.Text = text; }
 private void addComboBoxMacList(string item) { this.comboBoxMacList.Items.Add(item); }

 private System.Windows.Forms.Label labelMac;
 private System.Windows.Forms.TextBox textBoxMacField;
 public System.Windows.Forms.ComboBox comboBoxMacList;
 }
}
</pre>
<p>NetworkItem.cs </p>
<pre class="brush: plain;">
using System;
using System.Management;
using System.Windows.Forms;
using System.Collections;

public class NetworkItem
{
 public NetworkItem(int id, String desc, String mac)
 {
 this.id = id;
 this.description = desc;
 this.macaddr = mac;
 }

 public String getMacAddr()
 {
 return this.macaddr;
 }

 public String getDescription()
 {
 return this.description;
 }

 public int getID()
 {
 return this.id;
 }

 public override string ToString()
 {
 return this.description;
 }

 private String macaddr;
 private String description;
 private int id;

}
</pre>
<p>Program.cs </p>
<pre class="brush: plain;">
using System;
using System.Collections.Generic;
using System.Windows.Forms;

namespace MacGrabber
{
 static class Program
 {
 /// &lt;summary&gt;
 /// The main entry point for the application.
 /// &lt;/summary&gt;
 [STAThread]
 static void Main()
 {

 Application.EnableVisualStyles();
 Application.SetCompatibleTextRenderingDefault(false);
 Application.Run( new DefaultGUI() );

 }
 }
}
</pre>
<p>Auf wunsch publiziere ich gerne auch den Sourcecode in einem VS Projekt, bzw. die Binary in einem Archiv.</system></p>
<!-- google_ad_section_end -->
]]></content:encoded>
			<wfw:commentRss>http://www.informatik-blog.net/2009/08/25/mac-adresse-rausfinden-in-c/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
