获得机器IP地址
声明win32 API函数:
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
sle_1.text=ls_hostname
sle_2.text=ls_ipaddress
- 最新文章
- 在PB中实现串口编程[01-04]
- 如何获取鼠标是否进入控件[01-04]
- 如何实现HTML格式帮助文件的相关调用[01-04]
- pb6中获取应用所在路径及更改当前路径[01-04]
- Win32 API 与PB编程[01-04]
- 数据窗口中用Enter键替代Tab键切换栏目[01-04]
- 相关文章
- 如何用C++编程获得某台机器的IP地址?[01-03]
- Windows Vista系统下如何查看IP地址[01-03]
- Win 2003网络适配器的IP地址[01-03]
- 特殊用途的IP地址介绍[01-03]
- Win 98系统中IP地址的操作技巧[01-03]
- Windows 98系统中IP地址的操作技巧(多图)[01-03]
