欢迎光临
我们一直在努力

取得本机IP地址的方法两则-.NET教程,.NET Framework

建站超值云服务器,限时71元/月

方法1:(控件法)

新建工程,在工程中加入winsock控件和一个按钮控件

代码:

option explicit

private sub command1_click()

msgbox "当前计算机网卡ip:" & winsock1.localip

end sub

方法2:(api法)

新建工程,在工程中加入一个按钮控件

代码:

option explicit

private type wsadata

wversion as integer

whighversion as integer

szdescription(0 to 256)

szsystemstatus(0 to 128)

wmaxsockets as integer

dwvendorinfo as long

end type

private declare function wsastartup lib "wsock32.dll" (byval wversionrequired as long, lpwsadata as wsadata) as long

private declare function wsacleanup lib "wsock32.dll" () as long

private declare function gethostname lib "wsock32.dll" (byval szhost as string, byval dwhostlen as long) as long

private declare function gethostbyname lib "wsock32.dll" (byval szhost as string) as long

private declare sub copymemoryip lib "kernel32" alias "rtlmovememory" (hpvdest as any, byval hpvsource as long, byval cbcopy as long)

private function getipaddress() as string

on error goto z

dim wsa as wsadata

dim rval as long

dim shost as string * 256

dim lp as long

dim lpa as long

dim ipadr(0 to 3) as byte

rval = wsastartup((2 + &h100), wsa)

if rval = 0 then

gethostname shost, 256

lp = gethostbyname(shost)

if lp then

copymemoryip lpa, lp + 16, 4

copymemoryip ipadr(0), lpa, 4

getipaddress = cstr(ipadr(0)) & "." & cstr(ipadr(1)) & "." & cstr(ipadr(2)) & "." & cstr(ipadr(3))

end if

wsacleanup

end if

exit function

z:

getipaddress = ""

end function

private sub command1_click()

dim ret as string

ret = getipaddress

if ret <> "" then

msgbox "当前计算机网卡ip:" & ret

end if

end sub

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » 取得本机IP地址的方法两则-.NET教程,.NET Framework
分享到: 更多 (0)

相关推荐

  • 暂无文章