09. november 2002 - 12:58
#1
Tilføj "Microsoft Winsock Control x.x" funkre det ikke.
1.
tilføjet Microsoft Winsock Control x.x tryk [CTRL] + [T]
og find ....Winsock Control x.x på listen, set den på din Form1.
Private Sub Command1_Click()
Label1.Caption = Winsock1.LocalIP
End Sub
//>Rune
10. november 2002 - 03:01
#3
'så prøv med lidt API :)
Option Explicit
Const WSADescription_Len = 256
Const WSASYS_Status_Len = 128
Private Type HOSTENT
hName As Long
hAliases As Long
hAddrType As Integer
hLength As Integer
hAddrList As Long
End Type
Private Type WSADATA
wversion As Integer
wHighVersion As Integer
szDescription(0 To WSADescription_Len) As Byte
szSystemStatus(0 To WSASYS_Status_Len) As Byte
iMaxSockets As Integer
iMaxUdpDg As Integer
lpszVendorInfo As Long
End Type
Private Declare Function WSAStartup Lib "wsock32" _
(ByVal VersionReq As Long, WSADataReturn As WSADATA) As Long
Private Declare Function WSACleanup Lib "wsock32" () As Long
Private Declare Function WSAGetLastError Lib "wsock32" () As Long
Private Declare Function gethostbyaddr Lib "wsock32" _
(addr As Long, addrLen As Long, addrType As Long) As Long
Private Declare Function gethostbyname Lib "wsock32" _
(ByVal hostname As String) As Long
Private Declare Sub RtlMoveMemory Lib "kernel32" _
(hpvDest As Any, ByVal hpvSource As Long, ByVal cbCopy As Long)
Public Function GetIP() As String
On Error Resume Next
Dim hostent_addr As Long
Dim hst As HOSTENT
Dim hostip_addr As Long
Dim temp_ip_address() As Byte
Dim i As Integer
Dim ip_address As String
hostent_addr = gethostbyname(vbNullString)
If hostent_addr = 0 Then
Call MsgBox(9001, "Can't resolve hst")
Exit Function
End If
RtlMoveMemory hst, hostent_addr, LenB(hst)
RtlMoveMemory hostip_addr, hst.hAddrList, 4
ReDim temp_ip_address(1 To hst.hLength)
RtlMoveMemory temp_ip_address(1), hostip_addr, hst.hLength
For i = 1 To hst.hLength
ip_address = ip_address & temp_ip_address(i) & "."
Next
GetIP = Mid(ip_address, 1, Len(ip_address) - 1)
If Err.Number > 0 Then
Call MsgBox(Err.Number, Err.Description)
Err.Clear
End If
End Function
Private Sub Form_Load()
Dim udtWSAData As WSADATA
If WSAStartup(257, udtWSAData) Then MsgBox Err.LastDllError, Err.Description
Me.Caption = GetIP
End Sub
Private Sub Form_Unload(Cancel As Integer)
WSACleanup
End Sub