用VB 6.0怎样获得本机IP地址?
请教怎样用VB6.0获得本机IP地址,写上注释,最好代码简单易懂.谢谢,很着急,在线等不用第一楼方法不可行,第二楼不用控件,请问谁有别的办法获取本机IP,最好写上注释,...
请教怎样用VB6.0获得本机IP地址,写上注释,最好代码简单易懂.
谢谢,很着急,在线等
不用第一楼方法不可行,第二楼不用控件,请问谁有别的办法获取本机IP,最好写上注释, 展开
谢谢,很着急,在线等
不用第一楼方法不可行,第二楼不用控件,请问谁有别的办法获取本机IP,最好写上注释, 展开
5个回答
vip酷巴流体
2024-12-20 广告
2024-12-20 广告
作为酷巴流体控制(苏州)有限公司的工作人员,对于缓冲器的安装有所了解。以电梯缓冲器为例,其安装步骤如下:首先,确定缓冲器中心位置,使其与轿厢撞板中心对准,偏移不得超过20mm。其次,用水平尺测量缓冲器顶面,确保其水平误差小于2‰。如果为双缓...
点击进入详情页
本回答由vip酷巴流体提供
展开全部
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
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
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
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
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
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
工程->部件->Windows Winsock Control
在窗体上添加一个winsock控件,和一个CommandButton
Private Sub Command1_Click()
MsgBox Winsock1.LocalIP
End Sub
在窗体上添加一个winsock控件,和一个CommandButton
Private Sub Command1_Click()
MsgBox Winsock1.LocalIP
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
支持2楼那用这么复杂啊~~~控件就是用来用的~~~如果什么都用代码自己完成的话编程还有什么集体可言啊
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询