ercan_elo_bil
ercan_elo_bil

Reputation: 56

how to get clients mac address in delphi SOAP server?

I use delphi XE6 SOAP server WebModuleUnit and I can get client's IP address both WAN and LAN.

I can get client MAC address for use TCPIP ARP 'iphlpapi.dll' and 'SendARP' function. works LAN but doesnt work WAN network.

how to get Client's MAC address in work WAN?

My code(it doesn't work WAN )

type TIPAddr = u_long;
TMACAddr = array [0..5] of byte;
function SendARP (DestIP, SrcIP: TIPAddr; var TMacAddr: TMACAddr; var len: u_long): DWORD; stdcall; external 'iphlpapi.dll' name 'SendARP';
function GetMacAddress(Client: Ansistring):AnsiString;
///------------------------------
implementation
///------------------------------
function GetMacAddress(Client: Ansistring):AnsiString;
var
l: integer;
mac:TMACAddr;
Rets:Integer;
begin
  memset(@mac[0],0,sizeof(mac));
  l:= sizeof (TMACAddr);
 Rets:=sendARP(inet_addr (P_Char (Client)), 0, mac, l);
 result:=AnsiString(Format('%.2X-%.2X-%.2X-%.2X-%.2X-%.2X',[mac[0],mac[1],mac[2],mac[3],
                                                  mac[4],mac[5]]));
end;


unction TTRX_Service.ClientIP: AnsiString;
var
  WebDispatcher: IWebDispatcherAccess;
begin
  Result := '';
  if Supports(GetSOAPWebModule, IWebDispatcherAccess, WebDispatcher) then
    Result := AnsiString(WebDispatcher.Request.RemoteAddr);

  Debug('MAC Adress:%s',[GetMacAddress(Result)]);
end;

Could you please help me?

Upvotes: 3

Views: 1044

Answers (1)

Andy_D
Andy_D

Reputation: 2350

Quite simply, you can't. The clients on your WAN will be behind a router which will perform NAT (Network Address Translation) and traffic sent from them will appear to come from a single source. You may not have noticed but you will find that two clients from the same office on your WAN will have the same IP address. The only way to reliably obtain the MAC address is if your clients send it as a parameter as part of the web-service call, which will only work if they are running custom software rather than a web browser.

Upvotes: 4

Related Questions