用VB 6.0怎样获得本机IP地址?

请教怎样用VB6.0获得本机IP地址,写上注释,最好代码简单易懂.谢谢,很着急,在线等不用第一楼方法不可行,第二楼不用控件,请问谁有别的办法获取本机IP,最好写上注释,... 请教怎样用VB6.0获得本机IP地址,写上注释,最好代码简单易懂.
谢谢,很着急,在线等
不用第一楼方法不可行,第二楼不用控件,请问谁有别的办法获取本机IP,最好写上注释,
展开
 我来答
百度网友51349fc56
2006-09-30 · TA获得超过191个赞
知道答主
回答量:80
采纳率:100%
帮助的人:131万
展开全部
使用Winsock控件即可获得,方法如下:
Private Sub Command1_Click()
MsgBox Winsock1.LocalIP
End Sub
注意:Winsock控件不是标准工具箱中的控件,使用前要先在菜单"工程-部件"中选择,将"Microsoft Winsock Control 6.0"选中就可以了
vip酷巴流体
2024-12-20 广告
作为酷巴流体控制(苏州)有限公司的工作人员,对于缓冲器的安装有所了解。以电梯缓冲器为例,其安装步骤如下:首先,确定缓冲器中心位置,使其与轿厢撞板中心对准,偏移不得超过20mm。其次,用水平尺测量缓冲器顶面,确保其水平误差小于2‰。如果为双缓... 点击进入详情页
本回答由vip酷巴流体提供
在世贸天阶灌篮的高飞燕草
2006-09-30 · TA获得超过2378个赞
知道大有可为答主
回答量:2070
采纳率:0%
帮助的人:2021万
展开全部
Private Sub Command1_Click()
Dim aa As String
Dim strLocalIP As String
Dim winIP As Object
aa = aa & "本机电脑名称:" & Environ("computername") & vbCrLf
aa = aa & "本机用户名称:" & Environ("username") & vbCrLf
Set winIP = CreateObject("MSWinsock.Winsock")
strLocalIP = winIP.localip
MsgBox aa & "本机IP:" & strLocalIP
End Sub
本回答被提问者采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
顺眼还虔诚丶喜鹊8195
2006-09-30 · TA获得超过890个赞
知道小有建树答主
回答量:1287
采纳率:0%
帮助的人:939万
展开全部
Private Declare Function WSAGetLastError Lib "WSOCK32.DLL" () As Long
Private Declare Function WSAStartup Lib "WSOCK32.DLL" (ByVal wVersionRequired As Integer, lpWSAData As WSADATA) As Long
Private Declare Function WSACleanup Lib "WSOCK32.DLL" () As Long

Private Declare Function gethostname Lib "WSOCK32.DLL" (ByVal hostname$, ByVal HostLen As Long) As Long
Private Declare Function gethostbyname Lib "WSOCK32.DLL" (ByVal _
hostname$) As Long
Private Declare Sub RtlMoveMemory Lib "KERNEL32" (hpvDest As Any, ByVal hpvSource&, ByVal cbCopy&)
Private Const WS_VERSION_REQD = &H101
Private Const WS_VERSION_MAJOR = WS_VERSION_REQD \ &H100 And &HFF&
Private Const WS_VERSION_MINOR = WS_VERSION_REQD And &HFF&
Private Const MIN_SOCKETS_REQD = 1
Private Const SOCKET_ERROR = -1
Private Const WSADescription_Len = 256
Private Const WSASYS_Status_Len = 128

On Error Resume Next
lbsname.Caption = " --------"
lbslip.Caption = " --------"
lbship.Caption = " --------"
Dim hostname As String * 256
Dim hostent_addr As Long
Dim host As HOSTENT
Dim hostip_addr As Long
Dim temp_ip_address() As Byte
Dim i As Integer
Dim ip_address As String
Dim judge As Integer
judge = 0

If gethostname(hostname, 256) = SOCKET_ERROR Then
MsgBox "Windows Sockets error " & str(WSAGetLastError())
Exit Sub
Else
hostname = Trim$(hostname)
End If

hostent_addr = gethostbyname(hostname)

If hostent_addr = 0 Then
MsgBox "Winsock.dll is not responding."
Exit Sub
End If

RtlMoveMemory host, hostent_addr, LenB(host)
RtlMoveMemory hostip_addr, host.hAddrList, 4

lbsname.Caption = " " & hostname

'get all of the IP address if machine is multi-homed
Do
ReDim temp_ip_address(1 To host.hLength)
RtlMoveMemory temp_ip_address(1), hostip_addr, host.hLength

For i = 1 To host.hLength
ip_address = ip_address & temp_ip_address(i) & "."
Next
ip_address = Mid$(ip_address, 1, Len(ip_address) - 1)
If judge = 0 Then
lbslip.Caption = " " & ip_address
judge = 1
Else
lbship.Caption = " " & ip_address
End If
ip_address = ""
host.hAddrList = host.hAddrList + LenB(host.hAddrList)
RtlMoveMemory hostip_addr, host.hAddrList, 4
Loop While (hostip_addr <> 0)
参考:http://www.code365.com/programe/vb/code/200512142114072162.htm
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
快乐居家美食
2006-09-30 · TA获得超过1944个赞
知道大有可为答主
回答量:2392
采纳率:100%
帮助的人:1582万
展开全部
工程->部件->Windows Winsock Control

在窗体上添加一个winsock控件,和一个CommandButton
Private Sub Command1_Click()
MsgBox Winsock1.LocalIP
End Sub
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
百度网友a80bfc48c
2006-09-30 · TA获得超过342个赞
知道小有建树答主
回答量:378
采纳率:0%
帮助的人:311万
展开全部
支持2楼那用这么复杂啊~~~控件就是用来用的~~~如果什么都用代码自己完成的话编程还有什么集体可言啊
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 1条折叠回答
收起 更多回答(3)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式