Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,027

HOME > .NET Framework > Forum > จะดึงเอา MAC address ของ user/client มาเก็บไว้ด้วย asp.net จะได้ไหมครับ



 

จะดึงเอา MAC address ของ user/client มาเก็บไว้ด้วย asp.net จะได้ไหมครับ

 



Topic : 036733

Guest




ผมกำลังทำโปรเจคจบเรื่อง Wireless MAC authentication ครับ
ให้user สามารถเข้าใช้เน็ตและเข้าถึงทรัพยากรของ server ที่ผมสร้างได้ก็ต่อเมื่อ MAC address ของ user อยู่ในรายการกรอง MAC address ของ server

ผมได้สร้างหน้าเว็บลงทะเบียนให้ user ใหม่ลงทะเบียน MAC address ของ user ไว้ แต่ไม่รู้ว่าจะทำยังไงให้เวลา user กดยืนยันแล้ว ตัวเว็บจะส่ง MAC address ของ user ติดมากับข้อมูลลงทะเบียนของ user ด้วยน่ะครับ

ไม่ทราบว่า asp.net มี library หรือ ฟังกฺ์ชั่น ที่สามารถทำแบบที่ผมเขียนมาได้ไหมครับ



Tag : - - - -







Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2010-01-08 17:05:36 By : เอก View : 8684 Reply : 16
 

 

No. 1



โพสกระทู้ ( 3,144 )
บทความ ( 1 )

สมาชิกที่ใส่เสื้อไทยครีเอท

สถานะออฟไลน์


ไม่ได้ครับ ตาม tcp/ip model http จะทำให้อยู่ที่ใช้บนสุดของ model (process layer) ซึ่งจะคุยกันโดยใช้ ip address เท่านั้น

โดยมันจะสนกว่า client เครื่องนั้นมี mac address ใด เพราะมันถูกแปลงเป็น ip address

ตั้งแต่อยู่ที internet layer แล้ว ดังนั้นเราไม่สามารถเอาค่า mac address จากเครื่อง client

ได้ เพราะ mac adress จะอยู่ใน layer ต่ำกว่า layer ของ http

Mac Address






Date : 2010-01-08 19:50:20 By : tungman
 


 

No. 2



โพสกระทู้ ( 162 )
บทความ ( 0 )



สถานะออฟไลน์


Code (C#)

code โปรแกรม getmacaddress.cs ครับ

ใช้SDK complier ครับ


using System;
 using System.Diagnostics;
 using System.Net;
 using System.Net.NetworkInformation;
 using System.Runtime.InteropServices;
 using System.Text;
namespace Yours.Truly
 {
 public class GetMacAddressFromIPAddress
 {
 private const int PING_TIMEOUT = 1000;
 public GetMacAddressFromIPAddress()
 {
     }
 private string GetMacAddress(string ipAddress)
{
string macAddress = string.Empty;
 if (!IsHostAccessible(ipAddress)) return null;
  try
  {
 ProcessStartInfo processStartInfo = new ProcessStartInfo();
 Process process = new Process();
 processStartInfo.FileName = "nbtstat";
 processStartInfo.RedirectStandardInput = false;
 processStartInfo.RedirectStandardOutput = true;
 processStartInfo.Arguments = "-a " + ipAddress;
 processStartInfo.UseShellExecute = false;
 process = Process.Start(processStartInfo);
 int Counter = -1;
 while (Counter <= -1)
  {
 Counter =  macAddress.Trim().ToLower().IndexOf("mac address", 0);
   if (Counter > -1)
 {
 break;
 }
  macAddress = process.StandardOutput.ReadLine();
 }
 process.WaitForExit();
 macAddress = macAddress.Trim();
  }
    catch (Exception e)
  {
 Console.WriteLine("Failed because:" + e.ToString());
 }
 return macAddress;
 }
 #region Getting MAC from ARP
 [DllImport("iphlpapi.dll", ExactSpelling = true)]
 static extern int SendARP(int DestIP, int SrcIP, byte[] pMacAddr,ref uint PhyAddrLen);

 private string GetMACAddressFromARP(string hostNameOrAddress)
    {
          if (!IsHostAccessible(hostNameOrAddress)) return null;
      IPHostEntry hostEntry = Dns.GetHostEntry(hostNameOrAddress);
    if (hostEntry.AddressList.Length == 0)
  return null;
 byte[] macAddr = new byte[6];
  uint macAddrLen = (uint) macAddr.Length;
  if (SendARP((int) hostEntry.AddressList[0].Address, 0, macAddr,
 ref macAddrLen) != 0)
   return null;
  StringBuilder macAddressString = new StringBuilder();
   for (int i = 0; i < macAddr.Length; i++)
     {
    if (macAddressString.Length > 0)
     macAddressString.Append(":");
     macAddressString.AppendFormat("{0:x2}", macAddr[i]);
   }
   return macAddressString.ToString();
    }
   #endregion Getting MAC from ARP

  private static bool IsHostAccessible(string hostNameOrAddress)
     {
      Ping ping = new Ping();
 PingReply reply = ping.Send(hostNameOrAddress, PING_TIMEOUT);
 return reply.Status == IPStatus.Success;
  }
  [STAThread]
  static void Main(string[] args)
    {
    bool macRequired = true;
  while (macRequired)
   {
     Console.Write("Enter the IP : ");
  string ipAddress = Console.ReadLine();
  StringComparer cp = StringComparer.OrdinalIgnoreCase;
  if (cp.Compare(ipAddress, "Exit") == 0) break;
  GetMacAddressFromIPAddress getMacAddress = new GetMacAddressFromIPAddress();
  Console.WriteLine("Please wait while I try to find the MAC address...");
  string MacAddress = getMacAddress.GetMacAddress(ipAddress);
   Console.WriteLine(MacAddress);
   } 
     }
   } 
 } 



Date : 2010-01-09 13:48:48 By : superpheak
 

 

No. 3



โพสกระทู้ ( 3,144 )
บทความ ( 1 )

สมาชิกที่ใส่เสื้อไทยครีเอท

สถานะออฟไลน์


no.2 asp.net ไม่ใช่ win form นะ

แนะนำให้ใช้ ActiveX
Date : 2010-01-09 14:09:12 By : tungman
 


 

No. 4



โพสกระทู้ ( 162 )
บทความ ( 0 )



สถานะออฟไลน์


อธิบายเพิ่มครับ
จาก code ที่ให้มีวิธี getmacaddress client 2 function คือ funtion ที่ getโดยใช้ Protocol ARP และ
function ของ window คือ nbtstat code ที่ให้ใช้งาน function nbtstat ของ window ครับ

เหมือนกับเราเปิด dos ขึ้นมาแล้วพิมพ์ คำสั่ง nbtstat -a ตามด้วย IP address client จะไผลดังนี้ครับ

ข้อมูลที่ได้ คือ hostname,workgroup,mac address ครับ

C:\Documents and Settings\Manop Muangpia>nbtstat -a 192.168.1.39

Wireless Network Connection:
Node IpAddress: [192.168.1.53] Scope Id: []

NetBIOS Remote Machine Name Table

Name Type Status
---------------------------------------------
MONZA-PC <20> UNIQUE Registered
MONZA-PC <00> UNIQUE Registered
MSHOME <00> GROUP Registered
MSHOME <1E> GROUP Registered

MAC Address = 00-21-27-C2-17-3F


C:\Documents and Settings\Manop Muangpia>
Date : 2010-01-09 14:21:42 By : superpheak
 


 

No. 5



โพสกระทู้ ( 162 )
บทความ ( 0 )



สถานะออฟไลน์


C# เขียนได้ทั้ง Win form และ web forrm ครับ
Date : 2010-01-09 14:31:32 By : superpheak
 


 

No. 6



โพสกระทู้ ( 3,144 )
บทความ ( 1 )

สมาชิกที่ใส่เสื้อไทยครีเอท

สถานะออฟไลน์


แล้วจะต้องทำอย่างไรครับ ที่ให้ server สามารถเข้า access เครื่อง client ให้ส่ง mac ไปให้
Date : 2010-01-09 14:44:17 By : tungman
 


 

No. 7



โพสกระทู้ ( 162 )
บทความ ( 0 )



สถานะออฟไลน์


คือ ถ้า server เป็น windows ก็สามารถใช้ คำสั่ง nbtstat เพื่อร้องขอข้อมูลเครื่องใน network ได้ครับเราแค่เอามาใช้ผ่านทาง webform แทนที่จะพิมพ์ใน dos แทนครับ

ตัวอย่าง webform

Code (C#)
default.aspx

<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        Ip address :
        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
        <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" />
        <br />
        <asp:Literal ID="Literal1" runat="server"></asp:Literal></div>
    </form>
</body>
</html>

-----------------
defalut.aspx.cs
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Diagnostics;
using System.Net;
using System.Net.NetworkInformation;
using System.Runtime.InteropServices;
using System.Text;

public partial class _Default : System.Web.UI.Page
{

    protected void Page_Load(object sender, EventArgs e)
    {

    }


    protected void Button1_Click(object sender, EventArgs e)
    {
        string macAddress = string.Empty;
        ProcessStartInfo processStartInfo = new ProcessStartInfo();
        Process process = new Process();
        processStartInfo.FileName = "nbtstat";
        processStartInfo.RedirectStandardInput = false;
        processStartInfo.RedirectStandardOutput = true;
        processStartInfo.Arguments = "-a " + TextBox1.Text;
        processStartInfo.UseShellExecute = false;
        process = Process.Start(processStartInfo);
        int Counter = -1;
        while (Counter <= -1)
        {
            Counter = macAddress.Trim().ToLower().IndexOf("mac address", 0);
            if (Counter > -1)
            {
                break;
            }
            macAddress = process.StandardOutput.ReadLine();
        }
        process.WaitForExit();
        macAddress = macAddress.Trim();

        Literal1.Text = macAddress.ToString();

    }
}


Date : 2010-01-09 15:28:14 By : superpheak
 


 

No. 8



โพสกระทู้ ( 3,144 )
บทความ ( 1 )

สมาชิกที่ใส่เสื้อไทยครีเอท

สถานะออฟไลน์


เหมือนสั่งให้ client รัน command ของ dos เลย

ถ้าอย่างนั้น ถ้าผมเปลี่ยน command จาก "nbtstat" เป็น "format c:"

คราวนี้เวลา client เรียกหน้าเว็บนี้จาก server เครื่อง client ไม่เดี้ยงหมดเลยเหรอครับ

ปล.1 ผมอยากรู้ว่ามันทำได้จริงหรือ ถ้าทำได้มันอันตรายมากๆ
ปล.2 ผมยอมรับว่าถ้าเป็น winform สามารถทำได้แน่นอน เพราะมันสั่งรันในเครื่องตัวเอง แต่ webapp มันไม่เหมือนกันนะ
Date : 2010-01-09 16:34:48 By : tungman
 


 

No. 9

Guest


มาตอบคุณ tungman ครับ
คำสั่งนี้ รันที่เครื่อง server ครับ เหมือนคำสั่ง ping อะคับเช่นเครื่องเราเครื่อง A ping ไปเครื่อง B
เครื่อง B ไม่ได้ run โปรแกรมอะไรแต่เราก็ได้ message ตอบกลับจากเครื่อง B หลักการเดียวกัน
ครับ ปรกติอุปกรณ์ networkเขามี protocolที่ทำการแลกเปลี่ยนข้อมูลในระบบ network กันอยู่แล้ว

webform สามารถสร้าง โปรแกรมที่สามารถดู resource ของเครื่อข่าย server ได้ครับ เช่นเรา
สร้างโปรแกรม มาแล้ว up ขึ้น host ที่ไหนซักที่ เราสามารถดูได้ ชื่อserver,dns,ip,maxadress
sub netmark, แต่ถึงขั้น ให้ server format drive นี่ผมไม่แน่ใจครับ อย่างที่คุณ tungman บอก
ถ้าทำได้นี่เป็นเรื่องแน่ครับ ผมก็เพิ่งเริ่มศึกษา network programming ได้ไม่นาน ยังงูๆปลาๆ
อยู่ครับ
Date : 2010-01-09 21:46:50 By : superpheak
 


 

No. 10



โพสกระทู้ ( 3,144 )
บทความ ( 1 )

สมาชิกที่ใส่เสื้อไทยครีเอท

สถานะออฟไลน์


อืมพอจะเข้าใจแล้วครับ ต้องขอโทษด้วยตอนแรกคิดว่าจะใช้ http ไป request mac จากเครื่อง client

ก็เลยบอกว่าไม่ได้ ถ้าทำแบบนี้ก็ได้แหละครับ ให้ server gen network command ไป request ที่ client

คิดๆ ดูก็เคยเห็นโปรเจ็คทำนองนี้อยู่บ้างเหมือนกัน คือ ใช้เว็บสั่ง soft reset อุปกรณ์ network หรือ upload

visio ขึ้น server แล้วอ่าน sulotion ให้ gen command ไป config router ในเครือข่ายตาม solution

โดยไม่ต้องมานั่ง config ทีละตัว


งั้นต้องขอโทษอีกทีครับ และยินดีที่ได้แลกเปลี่ยนความรู้ครับ
Date : 2010-01-09 22:57:51 By : tungman
 


 

No. 11

Guest


ขอบคุณ
Date : 2011-01-15 23:02:00 By : +++
 


 

No. 12



โพสกระทู้ ( 2 )
บทความ ( 0 )



สถานะออฟไลน์


ผมชอบกระทู้นี้จัง +1000000 เลยครับ ได้ความรู้เยอะเลย ขอบคุณทุกท่านครับ ^^
Date : 2011-07-26 10:41:29 By : niphan
 


 

No. 13



โพสกระทู้ ( 153 )
บทความ ( 0 )



สถานะออฟไลน์


ชอบเหมือนกัน ได้ความรู้มากๆเลย
Date : 2011-07-26 11:40:14 By : stricken
 


 

No. 14



โพสกระทู้ ( 73 )
บทความ ( 0 )



สถานะออฟไลน์
Facebook

ชอบมากเหมือนกันคับ
Date : 2011-10-22 21:54:39 By : termja
 


 

No. 15

Guest


Run บน SharpDevelop 4.1 ได้ไหมครับ
Date : 2012-01-23 14:45:03 By : acomscie
 


 

No. 16

Guest


Code
<html>

 <!DOCTYPE  HTML  PUBLIC  "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
  <head>
        <title></title>
        <meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">
        <meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
        <script id="clientEventHandlersJS" language="javascript">

function Button1_onclick() 
{
  var locator = new ActiveXObject("WbemScripting.SWbemLocator");
  var service = locator.ConnectServer(".");
  var properties = service.ExecQuery("SELECT *  FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = 'True' And Not Description like '%wireless%' And Not Description like '%virtual%'" );
  var e = new Enumerator (properties);
  document.write("<table border=1>");
  dispHeading();
  for (;!e.atEnd();e.moveNext ())
  {
        var p = e.item ();
        document.write("<tr>");
        document.write("<td>" + p.Caption + "</td>");
        document.write("<td>" + p.IPFilterSecurityEnabled + "</td>");
        document.write("<td>" + p.IPPortSecurityEnabled + "</td>");
        document.write("<td>" + p.IPXAddress + "</td>");
        document.write("<td>" + p.IPXEnabled + "</td>");
        document.write("<td>" + p.IPXNetworkNumber + "</td>");
        document.write("<td>" + p.MACAddress + "</td>");
        document.write("<td>" + p.WINSPrimaryServer + "</td>");
        document.write("<td>" + p.WINSSecondaryServer + "</td>");
        document.write("</tr>");
  }
  document.write("</table>");
}

function dispHeading()
{
    document.write("<thead>");
    document.write("<td>Caption</td>");
    document.write("<td>IPFilterSecurityEnabled</td>");
    document.write("<td>IPPortSecurityEnabled</td>");
    document.write("<td>IPXAddress</td>");
    document.write("<td>IPXEnabled</td>");
    document.write("<td>IPXNetworkNumber</td>");
    document.write("<td>MACAddress</td>");
    document.write("<td>WINSPrimaryServer</td>");
    document.write("<td>WINSSecondaryServer</td>");
    document.write("</thead>");
}


        </script>
  </head>
  <body>

        <INPUT id="Button1" type="button" value="Button" name="Button1" language="javascript" onclick="return Button1_onclick()">
  </body>

 </html> 

Date : 2013-05-30 16:46:28 By : Alpha TH
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : จะดึงเอา MAC address ของ user/client มาเก็บไว้ด้วย asp.net จะได้ไหมครับ
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ FTP| ใส่แถวของตาราง ใส่คอลัมน์ตาราง| ตัวยก ตัวห้อย ตัวพิมพ์ดีด| ใส่โค้ด ใส่การอ้างถึงคำพูด| ใส่ลีสต์
smiley for :lol: smiley for :ken: smiley for :D smiley for :) smiley for ;) smiley for :eek: smiley for :geek: smiley for :roll: smiley for :erm: smiley for :cool: smiley for :blank: smiley for :idea: smiley for :ehh: smiley for :aargh: smiley for :evil:
Insert PHP Code
Insert ASP Code
Insert VB.NET Code Insert C#.NET Code Insert JavaScript Code Insert C#.NET Code
Insert Java Code
Insert Android Code
Insert Objective-C Code
Insert XML Code
Insert SQL Code
Insert Code
เพื่อความเรียบร้อยของข้อความ ควรจัดรูปแบบให้พอดีกับขนาดของหน้าจอ เพื่อง่ายต่อการอ่านและสบายตา และตรวจสอบภาษาไทยให้ถูกต้อง

อัพโหลดแทรกรูปภาพ

Notice

เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ
อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง

   
  เพื่อความปลอดภัยและการตรวจสอบ กระทู้ที่แทรกไฟล์อัพโหลดไฟล์จากที่อื่น อาจจะถูกลบทิ้ง
 
โดย
อีเมล์
บวกค่าให้ถูก
<= ตัวเลขฮินดูอารบิก เช่น 123 (หรือล็อกอินเข้าระบบสมาชิกเพื่อไม่ต้องกรอก)







Exchange: นำเข้าสินค้าจากจีน, Taobao, เฟอร์นิเจอร์, ของพรีเมี่ยม, ร่ม, ปากกา, power bank, แฟลชไดร์ฟ, กระบอกน้ำ

Load balance : Server 02
ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2024 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่