注册 登录
编程论坛 PowerBuilder

请问:PB如何获得计算机的IP地址和MAC

yebin5151 发布于 2007-06-21 08:53, 4944 次点击
想请教一个问题,怎么获得计算机的IP地址和MAC地址呢?
4 回复
#2
路過2007-06-21 09:57
#3
sam20802007-06-28 16:22

取得IP地址的方法:

1、定义一个名为s_wsadata的结构,如下:

unsignedinteger version

unsignedinteger highversion

character discription[257]

character systemstatus[129]

unsignedinteger maxsockets

unsignedinteger maxupddg

string vendorinfo

二、在Local External Funtions中作如下的声明:

function int WSAStartup( uint UIVersionRequested, ref s_WSAData lpWSAData ) library "wsock32.dll"

function int WSACleanup() library "wsock32.dll"

function int WSAGetLastError ( ) library "wsock32.dll"

function int gethostname ( ref string name, int namelen ) library "wsock32.dll"

function string GetHost(string lpszhost, ref blob lpszaddress ) library "pbws32.dll"


三、使用方法:

s_wsadata l_WSAData

string ls_HostName = space(128)

string ls_IpAddress

int li_version = 257

blob{4} lb_hostaddress


IF wsastartup ( li_version, l_WSAData ) = 0 THEN

IF gethostname ( ls_HostName, len(ls_HostName) ) < 0 THEN

messagebox("GetHostName",WSAGetLastError())

ELSE


GetHost(ls_HostName, lb_HostAddress)

ls_IpAddress = string(asc(string(blobmid(lb_HostAddress,1,1))),"000") + "."

ls_IpAddress += string(asc(string(blobmid(lb_HostAddress,2,1))),"000") + "."

ls_IpAddress += string(asc(string(blobmid(lb_HostAddress,3,1))),"000") + "."

ls_IpAddress += string(asc(string(blobmid(lb_HostAddress,4,1))),"000")


END IF


WSACleanup()

ELSE

messagebox("GetHostName",WSAGetLastError())

END IF


messagebox('ls_hostname: '+ls_hostname,'ls_ipaddress: '+ls_ipaddress)

获取MAC地址请看附件中的DLL及PBL
只有本站会员才能查看附件,请 登录

1