<?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; MAC-Adresse</title>
	<atom:link href="http://www.informatik-blog.net/tag/mac-adresse/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.informatik-blog.net</link>
	<description>Informatik &#38; Co.</description>
	<lastBuildDate>Mon, 19 Dec 2011 13:01:57 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1</generator>
		<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 [...]]]></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; title: ;">
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; title: ;">
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; title: ;">
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; title: ;">
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>2</slash:comments>
		</item>
		<item>
		<title>MAC-Adresse des Primären Netzwerkadapters auslesen in Java</title>
		<link>http://www.informatik-blog.net/2009/08/13/mac-adresse-des-primaren-netzwerkadapters-auslesen-in-java/</link>
		<comments>http://www.informatik-blog.net/2009/08/13/mac-adresse-des-primaren-netzwerkadapters-auslesen-in-java/#comments</comments>
		<pubDate>Thu, 13 Aug 2009 13:31:05 +0000</pubDate>
		<dc:creator>Emanuel</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[MAC-Adresse]]></category>
		<category><![CDATA[Netzwerk]]></category>

		<guid isPermaLink="false">http://www.informatik-blog.net/?p=595</guid>
		<description><![CDATA[Wie lese ich die MAC-Adresse in Java aus? Dies ist ganz einfach und funktioniert sowohl unter Linux als auch unter Windows und MAC OS X. Zuerst müssen wir durch die NIC Adapter durchloopen um festzustellen welcher kein LOOPBACK ist. Der LOOPBACK Adapter ist der eigene PC und besitzt keine MAC-Adresse. Danach ist es mit NetworkInterface [...]]]></description>
			<content:encoded><![CDATA[
<!-- google_ad_section_start -->
<p>Wie lese ich die MAC-Adresse in Java aus? Dies ist ganz einfach und funktioniert sowohl unter Linux als auch unter Windows und MAC OS X.</p>
<p>Zuerst müssen wir durch die NIC Adapter durchloopen um festzustellen welcher kein LOOPBACK ist. Der LOOPBACK Adapter ist der eigene PC und besitzt keine MAC-Adresse.<br />
<span id="more-595"></span><br />
Danach ist es mit NetworkInterface ziemlich einfach die MAC-Adresse rauszufinden.</p>
<pre class="brush: java; title: ;">
import java.net.NetworkInterface;
import java.util.Collections;

public class NetworkUtil {

 public static String getMacAddress() throws Exception {

 	String result = &quot;&quot;;
 	try {
 for (NetworkInterface ni : Collections.list(
 NetworkInterface.getNetworkInterfaces())) {
 byte[] hardwareAddress = ni.getHardwareAddress();

 if (hardwareAddress != null) {
 for (int i = 0; i &lt; hardwareAddress.length; i++) {
 result += String.format((i == 0 ? &quot;&quot; : &quot;&quot;) + &quot;%02X&quot;, hardwareAddress[i]);
 }
 if (result.length() &gt; 0 &amp;&amp; !ni.isLoopback()) { return result; }
 }
 }
 	} catch (Exception e) {
 		e.printStackTrace();
 	}
 return result;
 }
}
</pre>
<!-- google_ad_section_end -->
]]></content:encoded>
			<wfw:commentRss>http://www.informatik-blog.net/2009/08/13/mac-adresse-des-primaren-netzwerkadapters-auslesen-in-java/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

