Hi all,
I have managed to get my local IP, Hostname, and Port complted in code and works, but would like to get my Internet IP.
Can someonme help!
i.e
txtInternetIP.Text = Winsock1.InternetIP
Please help
Printable View
Hi all,
I have managed to get my local IP, Hostname, and Port complted in code and works, but would like to get my Internet IP.
Can someonme help!
i.e
txtInternetIP.Text = Winsock1.InternetIP
Please help
Your local IP is your internet ip
Sorry, but I thik I might have not explained myself very well.
My Local LAN IP is 192.168.0.1
My Internet IP is completely different - I would like this to be shown in my app.
Put this in a module
Code:'//////////////////////////////////////\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
' This code was generously donated by the MSDN on the Microsoft web site. Thank
' you to all these wonderful (grin) Microsoft programmers for finding such a
' (NOT) convenient way to get the real IP address.
'
' If possible this needs some Doevents statements
' It works great but seems to causing a delay in start up .
' Or is it because I reference it while there is no active connection ?
' signed , Private
'
'//////////////////////////////////////\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
Option Explicit
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
Private Const strWinsockNotResponding As String = "Winsock.dll is not responding"
Private Const strWinsockError As String = "Windows Sockets error "
Private Const strCouldNotGetIP As String = "Could not start Winsock services"
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 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&)
Function hibyte(ByVal wParam As Integer)
hibyte = wParam \ &H100 And &HFF&
End Function
Function lobyte(ByVal wParam As Integer)
lobyte = wParam And &HFF&
End Function
Function SocketsInitialize() As String
Dim WSAD As WSADATA
Dim iReturn As Integer
Dim sLowByte, sHighbyte, sMsg As String
iReturn = WSAStartup(WS_VERSION_REQD, WSAD)
If iReturn <> 0 Then
SocketsInitialize = strWinsockNotResponding
Exit Function
End If
If lobyte(WSAD.wversion) < WS_VERSION_MAJOR Or (lobyte(WSAD.wversion) = _
WS_VERSION_MAJOR And hibyte(WSAD.wversion) < WS_VERSION_MINOR) Then
sHighbyte = Trim$(Str$(hibyte(WSAD.wversion)))
sLowByte = Trim$(Str$(lobyte(WSAD.wversion)))
SocketsInitialize = "Windows Sockets version " & sLowByte & "." & sHighbyte & _
" is not supported by winsock.dll "
Exit Function
End If
'iMaxSockets is not used in winsock 2. So the following check is only
'necessary for winsock 1. If winsock 2 is requested,
'the following check can be skipped.
If WSAD.iMaxSockets < MIN_SOCKETS_REQD Then
SocketsInitialize = "This application requires a minimum of " & _
Trim$(Str$(MIN_SOCKETS_REQD)) & " supported sockets."
Exit Function
End If
SocketsInitialize = ""
End Function
Function SocketsCleanup() As String
Dim lReturn As Long
lReturn = WSACleanup()
If lReturn <> 0 Then
SocketsCleanup = "Socket error " & Trim$(Str$(lReturn)) & " occurred in Cleanup "
Exit Function
End If
End Function
Public Function GetLocalIPAddress(strIPAddresses() As String) As String
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 intCounter As Integer
Dim strErrorMessage As String
strErrorMessage = SocketsInitialize
If strErrorMessage = "" Then
If gethostname(hostname, 256) = SOCKET_ERROR Then
GetLocalIPAddress = strWinsockError & Str(WSAGetLastError())
Exit Function
Else
hostname = Trim$(hostname)
End If
hostent_addr = gethostbyname(hostname)
If hostent_addr = 0 Then
GetLocalIPAddress = strWinsockNotResponding
Exit Function
End If
RtlMoveMemory host, hostent_addr, LenB(host)
RtlMoveMemory hostip_addr, host.hAddrList, 4
'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)
ReDim Preserve strIPAddresses(intCounter)
strIPAddresses(intCounter) = ip_address
ip_address = ""
host.hAddrList = host.hAddrList + LenB(host.hAddrList)
RtlMoveMemory hostip_addr, host.hAddrList, 4
intCounter = intCounter + 1
Loop While (hostip_addr <> 0)
SocketsCleanup
GetLocalIPAddress = ""
Else
GetLocalIPAddress = strErrorMessage
End If
End Function
' Returns the user's Internet address, not one from his local pool of IP addresses (if
' the user has some LAN cards and/or a modem).
Public Function GetInternetAddress() As String
Dim strAllIPAddresses() As String
DoEvents
If GetLocalIPAddress(strAllIPAddresses()) = "" Then
GetInternetAddress = strAllIPAddresses(UBound(strAllIPAddresses()))
Else
GetInternetAddress = ""
End If
End Function
Who would have thought that the winsock ocx can't get your outside IP ? Thanks Microsoft .Code:txt_Ip = GetInternetAddress()
[]P
Sorry to be the "Bad" person in the thread but you should possibly look into the new "IPv6"
(Please note I haven't read ALL the Source above, but I would expect that it works out the IP address for a "IPv4")
If you want your application to be compatable with the "IPv6" I would look into it on the MSDN Site.
If you don't know what "IPv4" and "IPv6" are its quite simple.
IPv4 is this format " xxx.xxx.xxx.xxx "
IPv6 is this format " xxx.xxx.xxx.xxx.xxx.xxx "
Watch out Internet Programmers because the "IPv6" BETA versions are already out and running.
[Edited by Electroman on 11-05-2000 at 06:01 AM]
So how long do you think it's going to take for IPv6 to come out? I've heard loads about it, but everything still seems to be on the old system. (Linux looks like it has full support, based on what it says when it starts up)
Try this link for info about the IPv6
http://msdn.microsoft.com/downloads/...orm/tpipv6.asp
Sounds very interesting about IPv6, but according to MSDN it looks like it is only for Windows 2000. Is it going to be available for Windows 9x machines, but I suppose Windows 2000 is a more "network" related OS.
The way I see it is that for us Windows 9x users we will miss out on all the "fun".
Mind it is possible that MS will make it avalible for Windows 9x when it is TOTALLY ready for release.