unity3d助手吧 关注:16贴子:55
  • 0回复贴,共1

查看mac地址

只看楼主收藏回复


using UnityEngine;
using System.Collections;
using System.Net.NetworkInformation;
using System;
public class G : MonoBehaviour {
public GUIText gUIText;
// Use this for initialization
void Start () {
ShowNetworkInterfaces ();
}
// Update is called once per frame
void Update () {
}
void ShowNetworkInterfaces()
{
IPGlobalProperties computerProperties = IPGlobalProperties.GetIPGlobalProperties();
NetworkInterface[] nics = NetworkInterface.GetAllNetworkInterfaces();
gUIText.text=gUIText.text+"\n"+"Interface information for {0}.{1} "+
computerProperties.HostName+ computerProperties.DomainName;
if (nics == null || nics.Length < 1)
{
gUIText.text=gUIText.text+"\n"+" No network interfaces found.";
return;
}
gUIText.text=gUIText.text+"\n"+" Number of interfaces .................... : {0}"+ nics.Length;
foreach (NetworkInterface adapter in nics)
{
IPInterfaceProperties properties = adapter.GetIPProperties(); // .GetIPInterfaceProperties();
gUIText.text=gUIText.text+"\n"+adapter.Description;
gUIText.text=gUIText.text+"\n"+String.Empty.PadLeft(adapter.Description.Length,*=*);
gUIText.text=gUIText.text+"\n"+ "Interface type .......................... : {0}"+ adapter.NetworkInterfaceType;
gUIText.text=gUIText.text+"\n"+" Physical address ........................ : ";
PhysicalAddress address = adapter.GetPhysicalAddress();
byte[] bytes = address.GetAddressBytes();
for(int i = 0; i< bytes.Length; i++)
{
// Display the physical address in hexadecimal.
gUIText.text=gUIText.text+"\n"+("{0}"+ bytes[i].ToString("X2"));
// Insert a hyphen after each byte, unless we are at the end of the
// address.
if (i != bytes.Length -1)
{
gUIText.text=gUIText.text+"\n"+"-";
}
}
}
}
}


IP属地:浙江1楼2014-10-15 18:36回复