get the client mac address

本文介绍了一段使用C#实现的发送ARP请求的代码,并通过解析返回的MAC地址信息来识别客户端的物理地址。对于本地主机访问情况,会特别提示。代码示例包括了对用户主机地址的获取、ARP请求的发送以及MAC地址的解析过程。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Runtime.InteropServices;

namespace AspDoNet.Manage.CommonMethod
{
    public partial class FunctionList : System.Web.UI.Page
    {
        [DllImport("Iphlpapi.dll")]

        private static extern int SendARP(Int32 dest, Int32 host, ref Int64 mac, ref Int32 length);
        [DllImport("Ws2_32.dll")]
        private static extern Int32 inet_addr(string ip);
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                string userip = Request.UserHostAddress;
                string strClientIP = Request.UserHostAddress.ToString().Trim();
                Int32 ldest = inet_addr(strClientIP); 
                Int32 lhost = inet_addr("");   
                Int64 macinfo = new Int64();
                Int32 len = 6;
                int res = SendARP(ldest, 0, ref macinfo, ref len);
                string mac_src = macinfo.ToString("X");
                if (mac_src == "0")
                {
                    if (userip == "127.0.0.1")
                        Response.Write("visited Localhost!");
                    else
                        Response.Write("the IP from" + userip + "" + "<br>");
                    return;
                }

                while (mac_src.Length < 12)
                {
                    mac_src = mac_src.Insert(0, "0");
                }

                string mac_dest = "";

                for (int i = 0; i < 11; i++)
                {
                    if (0 == (i % 2))
                    {
                        if (i == 10)
                        {
                            mac_dest = mac_dest.Insert(0, mac_src.Substring(i, 2));
                        }
                        else
                        {
                            mac_dest = "-" + mac_dest.Insert(0, mac_src.Substring(i, 2));
                        }
                    }
                }

                Response.Write("welcome" + userip + "<br>" + ",the mac address is" + mac_dest + "."

                 + "<br>");
            }
            catch (Exception err)
            {
                Response.Write(err.Message);
            }
        }
   


    }
}

 

转载于:https://www.cnblogs.com/akingyao/archive/2013/06/05/3118379.html

解释一下下面的代码:bool vbss_task::handle_vbss_creation_event(const sCreationEvent &create_event) { vbss::sClientVBSS client_vbss = create_event.client_vbss; sMacAddr client_mac = client_vbss.client_mac; // You cannot create a VBSS via this method while a move for this VBSSID is ongoing auto existing_move = active_moves.get(client_vbss.vbssid); if (existing_move) { LOG(ERROR) << "Could not start VBSS creation for client with MAC address " << client_mac << "! Move already in progress for VBSSID " << client_vbss.vbssid << " (From radio " << existing_move->client_vbss.current_connected_ruid << " to radio " << existing_move->dest_ruid << ")"; return false; } auto existing_creation = active_creation_events.get(client_vbss.vbssid); if (existing_creation) { LOG(ERROR) << "Could not start VBSS creation for client with MAC address " << client_mac << "! Creation already in progress for VBSSID " << client_vbss.vbssid << " on the radio with UID " << existing_creation->dest_ruid; return false; } auto agent = m_database.get_agent_by_radio_uid(client_vbss.current_connected_ruid); if (!agent) { LOG(ERROR) << "Could not start VBSS creation for client with MAC address " << client_mac << "! Could not find agent for radio uid " << client_vbss.current_connected_ruid; return false; } active_creation_events.add(client_vbss.vbssid, client_vbss, create_event.dest_ruid, create_event.ssid, create_event.password); // VBSS spec states that during a move, the Agent should process/reply to the creation request // within some time span. So, spin up a timer at this point in the move state machine. begin_timer_for_timed_event(client_vbss, VBSS_EVENT_TIMEOUT_MS); sMacAddr agent_mac = agent->al_mac; if (client_vbss.client_is_associated) { // Client is already associated, Must have the Security Context to create a VBSS if (!vbss::vbss_actions::send_client_security_ctx_request(agent_mac, client_vbss, m_database)) { LOG(ERROR) << "Could not start VBSS creation for client with MAC address " << client_mac << "! Client Security Context Request failed to send!"; return false; } return true; } // Client is not associated, just request VBSS creation if (!vbss::vbss_actions::create_vbss(client_vbss, create_event.dest_ruid, create_event.ssid, create_event.password, nullptr, m_database)) { LOG(ERROR) << "Could not start VBSS creation for client with MAC address " << client_mac << "! Create VBSS Request failed to send!"; return false; } return true; }
08-20
Hi YuFei, I have a question on multicast streaming through Deco26 FAP and RE. Here is the related ticket link: Bug 1105517 – [Multicast]2 units wireless mesh, when a speedtest is conducted by deco, the RE clients cannot play multicast content. And here is my test setup: https://pdconfluence.tp-link.com/pages/viewpage.action?pageId=166851882 I have run several tests and here is a summary of observation: 1: FAP - - wifi - - RE connection:   This is the ticket reported scenario. And traffic is captured at FAP egress and VLC client PC: The UDP packets are duplicated at client side while only one same ID packet is captured at FAP egress, file FAP_withSFE.png in the attachment. Video streaming is bad. 2: FAP — wifi — RE connection, without SFE running in FAP     By this transmission, with tcpdump running at same points as above, there is no duplicated packet received at client. Video playback is good. And Destination MAC address becomes specific target MAC address, a unicast. File FAP_withoutSFE.png in the attachment. 3: FAP — cable — RE connection, with SFE running in FAP:     By this transmission, there is no duplicated packet received at client. Video playback is good at client. And DST MAC address stays multicast MAC address. Can you please share some advice? 1: in the 1st test case, I am wondering if duplicated are generated in the Linux host, instead wifi driver? 2: in the 2nd case, is it supposed that removal/disable of SFE makes multicast MAC address into unicast MAC address? Thank you very much in advance for your suggestion
最新发布
08-29
请解释一下下面的代码:/** * @brief Initiates a VBSS Request with the Creation TLV at the current Radio and the given parameters * * Example of usage: * ubus call Device.WiFi.DataElements.Network.Device.1.Radio.1 TriggerVBSSCreation * '{"vbssid": "aa:bb:cc:dd:ee:ff", "client_mac": "aa:bb:cc:dd:ee:ff", "ssid": "prplMeshNetwork", "pass": "prplmeshpass"}' * */ amxd_status_t trigger_vbss_creation(amxd_object_t *object, amxd_function_t *func, amxc_var_t *args, amxc_var_t *ret) { auto controller_ctx = g_database->get_controller_ctx(); if (!controller_ctx) { LOG(ERROR) << "Failed to get controller context."; return amxd_status_unknown_error; } amxc_var_t value; amxc_var_init(&value); amxd_object_get_param(object, "ID", &value); std::string radio_mac_str = amxc_var_constcast(cstring_t, &value); if (radio_mac_str.empty()) { LOG(ERROR) << "agent_mac_str is empty"; return amxd_status_parameter_not_found; } std::string vbssid_str = GET_CHAR(args, "vbssid"); std::string client_mac_str = GET_CHAR(args, "client_mac"); std::string ssid = GET_CHAR(args, "ssid"); std::string password = GET_CHAR(args, "pass"); if (password.size() < 8) { LOG(ERROR) << "Failed to create VBSS via NB API! Password provided is less than 8 characters!"; return amxd_status_invalid_value; } sMacAddr vbssid, client_mac = {}; sMacAddr radio_uid = tlvf::mac_from_string(radio_mac_str); if (!tlvf::mac_from_string(vbssid.oct, vbssid_str)) { LOG(ERROR) << "Failed to create VBSS via NB API! Given VBSSID (" << vbssid_str << ") is not a valid MAC address"; return amxd_status_invalid_value; } if (!tlvf::mac_from_string(client_mac.oct, client_mac_str)) { LOG(ERROR) << "Failed to create VBSS via NB API! Given Client MAC (" << client_mac_str << ") is not a valid MAC address"; return amxd_status_invalid_value; } if (!controller_ctx->trigger_vbss_creation(radio_uid, vbssid, client_mac, ssid, password)) { LOG(ERROR) << "Failed to send VBSS Creation Request for client: " << client_mac_str << " and VBSSID " << vbssid_str << " on radio " << radio_mac_str; return amxd_status_unknown_error; } return amxd_status_ok; }
08-20
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值