超急!如何用代码实现MAC与IP的绑定! ( 积分: 100 )

  • 主题发起人 主题发起人 hzm7512
  • 开始时间 开始时间
H

hzm7512

Unregistered / Unconfirmed
GUEST, unregistred user!
超急!如何用代码实现MAC与IP的绑定!
 
超急!如何用代码实现MAC与IP的绑定!
 
通过IP取MAC地址

uses
WinSock;

Function sendarp(ipaddr:ulong;
temp:dword;
ulmacaddr:pointer;
ulmacaddrleng:pointer) : DWord; StdCall; External 'Iphlpapi.dll' Name 'SendARP';

procedure TForm1.Button1Click(Sender: TObject);
var
myip:ulong;
mymac:array[0..5] of byte;
mymaclength:ulong;
r:integer;
begin
myip:=inet_addr(PChar('192.168.6.180'));
mymaclength:=length(mymac);
r:=sendarp(myip,0,@mymac,@mymaclength);
label1.caption:='errorcode:'+inttostr(r);
label2.caption:=format('%2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x',[mymac[0],mymac[1],mymac[2],mymac[3],mymac[4],mymac[5]]);
end;
 
用楼上的方法获得IP对应的MAC

然后用shellexecute执行ARP -S IP MAC来实现绑定

不过要在服务器端运行这个东西
 
"然后用shellexecute执行ARP -S IP MAC来实现绑定 " 这只是静态绑定吧?好像我还是可以任意改变IP呀,而且网络也不受影响.
 
哦? 我没试过 呵呵,只知道这是在服务器端用来绑定MAC-IP的命令
下面是ARP的说明

Displays and modifies the IP-to-Physical address translation tables used by
address resolution protocol (ARP).

ARP -s inet_addr eth_addr [if_addr]
ARP -d inet_addr [if_addr]
ARP -a [inet_addr] [-N if_addr]

-a Displays current ARP entries by interrogating the current
protocol data. If inet_addr is specified, the IP and Physical
addresses for only the specified computer are displayed. If
more than one network interface uses ARP, entries for each ARP
table are displayed.
-g Same as -a.
inet_addr Specifies an internet address.
-N if_addr Displays the ARP entries for the network interface specified
by if_addr.
-d Deletes the host specified by inet_addr. inet_addr may be
wildcarded with * to delete all hosts.
-s Adds the host and associates the Internet address inet_addr
with the Physical address eth_addr. The Physical address is
given as 6 hexadecimal bytes separated by hyphens. The entry
is permanent.
eth_addr Specifies a physical address.
if_addr If present, this specifies the Internet address of the
interface whose address translation table should be modified.
If not present, the first applicable interface will be used.
Example:
> arp -s 157.55.85.212 00-aa-00-62-c6-09 .... Adds a static entry.
> arp -a .... Displays the arp table.
 
发送UDP数据包
 
http://www.pconline.com.cn/pcedu/soft/lan/jywgl/10207/79487.html

mac和ip绑定,用代码好像比较困难吧
 
http://www.delphibbs.com/delphibbs/dispq.asp?lid=388180
 
本文引用通告地址:
http://blog.csdn.net/shanyou/services/trackbacks/60724.aspx
 
多人接受答案了。
 
后退
顶部