一个简单取得本机IP,电脑名称,MAC地址的方法

 1 unit  Unit1;
 2
 3 interface
 4
 5 uses
 6   Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
 7   Dialogs, StdCtrls,WinSock, Sockets;
 8
 9 type
10   TForm1  =   class (TForm)
11     Button1: TButton;
12      procedure  Button1Click(Sender: TObject);
13    private
14      {  Private declarations  }
15    public
16      {  Public declarations  }
17    end ;
18
19 var
20   Form1: TForm1;
21   Function sendarp(ipaddr:ulong;temp:dword;ulmacaddr:pointer;ulmacaddrleng:pointer):DWord;StdCall;External  ' Iphlpapi.dll '  Name  ' SendARP ' ;
22 implementation
23
24 { $R *.dfm }
25
26 procedure  TForm1.Button1Click(Sender: TObject);
27 var
28   mymac: array [ 0 .. 5 of  byte;
29   mymaclength:ulong;
30   tmp:TInAddr;
31   sip: string ;
32   tp:ttcpclient;
33 begin
34   sip: = ' 172.20.104.111 ' ;
35   mymaclength: = length(mymac);
36    if  sendarp(inet_addr(pChar(sip)), 0 ,@mymac,@mymaclength) = 0   then
37    begin
38     tmp.S_addr: = inet_addr(pChar(sip));
39     ShowMessage(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 ]]));
40    end ;
41   tp: = ttcpclient.create(self);
42   tp.close;
43   tp.open;
44   ShowMessage(tp.LocalHostName);
45   ShowMessage(tp.LocalHostAddr);
46   tp.close;
47 end ;
48
49 end .
50

转载于:https://www.cnblogs.com/zhaoyong/archive/2009/07/03/1515997.html

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值