Hallo Nepster
wenn das noch aktuell ist hätte ich noch eine Altnernative die ohne Internet Seite und Winsock auskommt.
(Sollte auch weil Winsock die LocalIP nicht ändert, das heißt nur beim Start des Progs ausliest und dann immer die Alte ausgibt).
Option Explicit
' Main
Public Function LocalIP()
TmpComputerName=environ("computername")
' geht glaub ich nur WinXP sonst muss es halt anders
' rausbekommen (z.B. doch über winsock.LocalHostName)
LocalIP=GetIPFromHost(TmpComputerName)
End Function
' ADDITIONAL
' einfach in ein Modul kopieren
' Benötigte API-Deklarationen
Private Const WS_VERSION_REQD As Long = &H101
Private Const MAX_WSADescription = 256
Private Const MAX_WSASYSStatus = 128
Private Const ERROR_SUCCESS = 0&
Private Type WSAData
wVersion As Integer
wHighVersion As Integer
szDescription(0 To MAX_WSADescription) As Byte
szSystemStatus(0 To MAX_WSASYSStatus) As Byte
wMaxSockets As Integer
wMaxUDPDG As Integer
dwVendorInfo As Long
End Type
Private Type HOSTENT
hName As Long
hAliases As Long
hAddrType As Integer
hLen As Integer
hAddrList 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 gethostbyname Lib "WSOCK32.DLL" ( _
ByVal szHost As String) As Long
Private Declare Function gethostbyaddr Lib "WSOCK32.DLL" ( _
lpIP As Long, _
ByVal nLength As Integer, _
ByVal nType As Long) As Long
Private Declare Function inet_addr Lib "WSOCK32.DLL" _
(ByVal szIP As String) As Long
Private Declare Sub CopyMemory Lib "kernel32" _
Alias "RtlMoveMemory" ( _
lpDest As Any, _
ByVal lpSource As Long, _
ByVal cbCopy As Long)
' Ermittelt den Rechner-/Servername (Hostname)
' anhand einer IP-Adresse
Public Function GetHostFromIP(ByVal sIPAddress As String) As String
Dim WSAD As WSAData
Dim nIP As Long
Dim nResult As Long
Dim nLen As Long
Dim sHostname As String
Dim m_Host As HOSTENT
If WSAStartup(WS_VERSION_REQD, WSAD) = ERROR_SUCCESS Then
nIP = inet_addr(sIPAddress)
nResult = gethostbyaddr(nIP, 4, 2)
If nResult <> 0 Then
nLen = Len(m_Host)
sHostname = String$(260, 0)
CopyMemory m_Host, nResult, nLen
CopyMemory ByVal sHostname, m_Host.hName, 260
sHostname = Left$(sHostname, InStr(sHostname, Chr$(0)) - 1)
End If
Call WSACleanup
End If
GetHostFromIP = sHostname
End Function
' Ermittelt die IP-Adresse anhand eines
' Rechner-/Server-Namens (Hostname)
Public Function GetIPFromHost(ByVal sHostname As String) As String
Dim WSAD As WSAData
Dim nHost As Long
Dim nIP As Long
Dim nTemp() As Byte
Dim m_Host As HOSTENT
Dim sIPAddress As String
Dim i As Long
If WSAStartup(WS_VERSION_REQD, WSAD) = ERROR_SUCCESS Then
nHost = gethostbyname(ByVal Replace(sHostname, "\", ""))
If nHost <> 0 Then
CopyMemory m_Host, ByVal nHost, ByVal Len(m_Host)
CopyMemory nIP, ByVal m_Host.hAddrList, ByVal 4
ReDim nTemp(1 To m_Host.hLen)
CopyMemory nTemp(1), ByVal nIP, ByVal m_Host.hLen
For i = 1 To m_Host.hLen
sIPAddress = sIPAddress & nTemp(i) & "."
Next i
sIPAddress = Left$(sIPAddress, Len(sIPAddress) - 1)
End If
Call WSACleanup
End If
GetIPFromHost = sIPAddress
End Function |