日常茶飯事

아래 예제 참조 하세요.

간단합니다. ㅎㅎ

 

public static String getMacAddress(String ipaddress)
{
    String queryStr = "select * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled='TRUE'";
    System.Management.ObjectQuery objectQuery = new System.Management.ObjectQuery(queryStr);
    System.Management.ManagementObjectSearcher searcher = new System.Management.ManagementObjectSearcher(objectQuery);
    System.Management.ManagementObjectCollection mos = searcher.Get();
    String macAddress = null;

    foreach (System.Management.ManagementObject mo in mos)
    {
 if (Utils.isEmpty(ipaddress))
 {
     macAddress = mo["MACAddress"].ToString();
     break;
 }
 else
 {
     String[] address = (String[])mo["IPAddress"];
     if (ipaddress.Equals(address[0]))
     {
  macAddress = mo["MACAddress"].ToString();
  break;
     }
 }
    }

    return macAddress;
}

public static String getIpAddress(String macaddress)
{
    String queryStr = "select * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled='TRUE'";
    System.Management.ObjectQuery objectQuery = new System.Management.ObjectQuery(queryStr);
    System.Management.ManagementObjectSearcher searcher = new System.Management.ManagementObjectSearcher(objectQuery);
    System.Management.ManagementObjectCollection mos = searcher.Get();
    String IpAddress = null;

    foreach (System.Management.ManagementObject mo in mos)
    {
 if (Utils.isEmpty(macaddress))
 {
     String[] address = (String[])mo["IPAddress"];
     IpAddress = address[0];
     break;
 }
 else
 {
     String mac = mo["MACAddress"].ToString();
     if (macaddress.Equals(mac))
     {
  String[] address = (String[])mo["IPAddress"];
  IpAddress = address[0];
  break;
     }
 }
    }

    return IpAddress;
}

'프로그램개발 > Tip!!' 카테고리의 다른 글

MS Timezone  (0) 2016.08.20
[C#] 웹서버를 만들어 봅시다.  (2) 2015.12.25
[C#]ASC II Code  (0) 2015.11.14
[C#] 토렌토 파일을 읽어 봅시다.  (0) 2015.10.17
[c#] Mac Address/ Ip Address 가져오기  (0) 2012.08.09
[PHP]이메일 존재 여부 검사기~  (0) 2007.10.01

Comment +0