Skip to content
This repository was archived by the owner on Jan 12, 2024. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 30 additions & 20 deletions MACAddressTool/Form1.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

47 changes: 38 additions & 9 deletions MACAddressTool/Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
using Microsoft.Win32;
using System.Net.NetworkInformation;
using System.Text.RegularExpressions;

using System.Threading;

namespace MACAddressTool
{
Expand Down Expand Up @@ -110,14 +110,17 @@ public string RegistryKey
/// <summary>
/// Get the NetworkAddress registry value of this adapter.
/// </summary>
public string RegistryMac {
public string RegistryMac
{
get
{
try
{
using (RegistryKey regkey = Registry.LocalMachine.OpenSubKey(this.RegistryKey, false))
{
return regkey.GetValue("NetworkAddress").ToString();
var value = regkey.GetValue("NetworkAddress");
if (value != null) return regkey.GetValue("NetworkAddress").ToString();
else return null;
}
}
catch
Expand Down Expand Up @@ -176,7 +179,7 @@ public bool SetRegistryMac(string value)
regkey.SetValue("NetworkAddress", value, RegistryValueKind.String);
else
regkey.DeleteValue("NetworkAddress");


return true;
}
Expand Down Expand Up @@ -278,19 +281,41 @@ public Form1()
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
private List<Adapter> get_adapters_list()
{
List<Adapter> adapters = new List<Adapter> { };
/* Windows generally seems to add a number of non-physical devices, of which
* we would not want to change the address. Most of them have an impossible
* MAC address. */
foreach (NetworkInterface adapter in NetworkInterface.GetAllNetworkInterfaces().Where(
a => Adapter.IsValidMac(a.GetPhysicalAddress().GetAddressBytes(), true)
).OrderByDescending(a => a.Speed))
{
AdaptersComboBox.Items.Add(new Adapter(adapter));
adapters.Add(new Adapter(adapter));
}

return adapters;
}

private void Form1_Load(object sender, EventArgs e)
{
AdaptersComboBox.Items.Add("Loading...");
AdaptersComboBox.SelectedIndex = 0;
AdaptersComboBox.Enabled = false;
Thread t = new Thread(() =>
{
var adapters = get_adapters_list();
AdaptersComboBox.Invoke((MethodInvoker)delegate
{
AdaptersComboBox.Items.Clear();
foreach (Adapter adapter in adapters)
{
AdaptersComboBox.Items.Add(adapter);
AdaptersComboBox.Enabled = true;
AdaptersComboBox.SelectedIndex = 0;
}
});
});
t.Start();
}

/// <summary>
Expand All @@ -299,8 +324,12 @@ private void Form1_Load(object sender, EventArgs e)
private void UpdateAddresses()
{
Adapter a = AdaptersComboBox.SelectedItem as Adapter;
this.CurrentMacTextBox.Text = a.RegistryMac;
this.ActualMacLabel.Text = a.Mac;
if (a != null)
{
this.CurrentMacTextBox.Text = a.RegistryMac;
this.ActualMacLabel.Text = a.Mac;
}

}

private void AdaptersComboBox_SelectedIndexChanged(object sender, EventArgs e)
Expand Down
39 changes: 39 additions & 0 deletions MACAddressTool/MACAddressTool.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,22 @@
<AssemblyName>MAC Address Tool</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<IsWebBootstrapper>false</IsWebBootstrapper>
<PublishUrl>C:\Programs\MacAddressTool\</PublishUrl>
<Install>true</Install>
<InstallFrom>Disk</InstallFrom>
<UpdateEnabled>false</UpdateEnabled>
<UpdateMode>Foreground</UpdateMode>
<UpdateInterval>7</UpdateInterval>
<UpdateIntervalUnits>Days</UpdateIntervalUnits>
<UpdatePeriodically>false</UpdatePeriodically>
<UpdateRequired>false</UpdateRequired>
<MapFileExtensions>true</MapFileExtensions>
<ApplicationRevision>0</ApplicationRevision>
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
<UseApplicationTrust>false</UseApplicationTrust>
<PublishWizardCompleted>true</PublishWizardCompleted>
<BootstrapperEnabled>true</BootstrapperEnabled>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
Expand All @@ -34,6 +50,21 @@
<PropertyGroup>
<ApplicationManifest>app.manifest</ApplicationManifest>
</PropertyGroup>
<PropertyGroup>
<ManifestCertificateThumbprint>BD6BABBFEBA46A13A8376FE300A123EA72E78D00</ManifestCertificateThumbprint>
</PropertyGroup>
<PropertyGroup>
<ManifestKeyFile>MACAddressTool_TemporaryKey.pfx</ManifestKeyFile>
</PropertyGroup>
<PropertyGroup>
<GenerateManifests>false</GenerateManifests>
</PropertyGroup>
<PropertyGroup>
<SignManifests>false</SignManifests>
</PropertyGroup>
<PropertyGroup>
<TargetZone>LocalIntranet</TargetZone>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Configuration" />
Expand Down Expand Up @@ -62,10 +93,18 @@
<DependentUpon>Form1.cs</DependentUpon>
</EmbeddedResource>
<None Include="app.manifest" />
<None Include="MACAddressTool_TemporaryKey.pfx" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<ItemGroup>
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
<Visible>False</Visible>
<ProductName>.NET Framework 3.5 SP1</ProductName>
<Install>false</Install>
</BootstrapperPackage>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
Expand Down
16 changes: 6 additions & 10 deletions MACAddressTool/app.manifest
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<asmv1:assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1" xmlns:asmv1="urn:schemas-microsoft-com:asm.v1" xmlns:asmv2="urn:schemas-microsoft-com:asm.v2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<assemblyIdentity version="1.0.0.0" name="MyApplication.app"/>
<assemblyIdentity version="1.0.0.0" name="MyApplication.app" />
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
<security>
<requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
Expand All @@ -18,29 +18,26 @@
-->
<requestedExecutionLevel level="highestAvailable" uiAccess="false" />
</requestedPrivileges>
<applicationRequestMinimum>
<defaultAssemblyRequest permissionSetReference="Custom" />
<PermissionSet ID="Custom" SameSite="site" Unrestricted="true" />
</applicationRequestMinimum>
</security>
</trustInfo>

<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
<application>
<!-- A list of all Windows versions that this application is designed to work with.
Windows will automatically select the most compatible environment.-->

<!-- If your application is designed to work with Windows Vista, uncomment the following supportedOS node-->
<!--<supportedOS Id="{e2011457-1546-43c5-a5fe-008deee3d3f0}"></supportedOS>-->

<!-- If your application is designed to work with Windows 7, uncomment the following supportedOS node-->
<!--<supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}"/>-->

<!-- If your application is designed to work with Windows 8, uncomment the following supportedOS node-->
<!--<supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}"></supportedOS>-->

<!-- If your application is designed to work with Windows 8.1, uncomment the following supportedOS node-->
<!--<supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}"/>-->

</application>
</compatibility>

<!-- Enable themes for Windows common controls and dialogs (Windows XP and later) -->
<!-- <dependency>
<dependentAssembly>
Expand All @@ -54,5 +51,4 @@
/>
</dependentAssembly>
</dependency>-->

</asmv1:assembly>
</asmv1:assembly>