Re: getting IP adress using hostname (IN CHINESE ENVIROMENT)
From: Randy Birch (rgb_removethis_at_mvps.org)
Date: 08/12/04
- Next message: Wally: "List of countries"
- Previous message: Abdullah Ali: "getting IP adress using hostname (IN CHINESE ENVIROMENT)"
- In reply to: Abdullah Ali: "getting IP adress using hostname (IN CHINESE ENVIROMENT)"
- Messages sorted by: [ date ] [ thread ]
Date: Thu, 12 Aug 2004 18:22:53 -0400
This might work - just updated - ...
http://vbnet.mvps.org/code/network/iplookup.htm ... but I suspect the
problem is the use of the ANSI APIs on systems returning Unicode strings
(the 'W' versions of the APIs). This page also provides the inet_ntoa API
that converts the value at a particular address into the dot-string notation
for IP addresses, without the need for IPToText().
-- Randy Birch MVP Visual Basic http://vbnet.mvps.org/ Please respond only to the newsgroups so all can benefit. "Abdullah Ali" <abdullah@visual-2000.com> wrote in message news:1e3c5f17.0408121058.43106ef8@posting.google.com... : Hello, : : I am currectly working on a project within a chinese enviroment. It is : an Access project using VBA. I have a function that returns an IP : address based on the input of a HOST name. : : The function works properly on my side, but when I implement the same : function in a chinese enviroment, the error occurs at "apiCopyMemory : ByVal sAddress, ByVal ptrIPAddress, hstHost.hLength" in the function : GETIPFROMHOSTNAME. : : This is supposed to return a ASCII value, and then from there , it : will convert the ASCII to a IP string using the function IPTOTEXT : (this is where the 'real' crash occurs : : Instead, it returns 1 chinese char, which cannot be read by the : function IPTOTEXT. : : : Why is it doing this and is there a way to resolve this problem : : ANY help is appreciated : : ---------------------------------------------------------------------------------------------------- : Private Declare Sub apiCopyMemory Lib "kernel32" Alias "RtlMoveMemory" : (xDest As Any, xSource As Any, ByVal nBytes As Long) : : : Public Function GetIPFromHostName(ByVal sHostName As String) As String : 'converts a host name to an IP address. : : Dim nBytes As Long : Dim ptrHosent As Long : Dim hstHost As HOSTENT : Dim ptrName As Long : Dim ptrAddress As Long : Dim ptrIPAddress As Long : Dim sAddress As String 'declare this as Dim sAddress(1) As String : if you want 2 ip addresses returned : : 'try to initalize the socket : If InitializeSocket() = True Then : : 'try to get the IP : ptrHosent = apiGetHostByName(sHostName & vbNullChar) : : If ptrHosent <> 0 Then : : 'get the IP address : apiCopyMemory hstHost, ByVal ptrHosent, LenB(hstHost) : apiCopyMemory ptrIPAddress, ByVal hstHost.hAddrList, 4 : : 'fill buffer : sAddress = Space$(4) : 'if you want multiple domains returned, : 'fill all items in sAddress array with 4 spaces : : ----> THIS IS WHERE THE CHINESE CHAR POPS UP IN sAddress <------ : ----> INSTEAD OF ASCII CODE <----- : apiCopyMemory ByVal sAddress, ByVal ptrIPAddress, : hstHost.hLength : : 'change this to : 'CopyMemory ByVal sAddress(0), ByVal ptrIPAddress, : hstHost.hLength : 'if you want an array of ip addresses returned : '(some domains have more than one ip address associated : with it) : : 'get the IP address : GetIPFromHostName = IPToText(sAddress) : 'if you are using multiple addresses, you need : IPToText(sAddress(0)) & "," & IPToText(sAddress(1)) : 'etc : End If : Else : GetIPFromHostName = "NO" : End If : End Function : : : -----> CAUSING THIS FUNCTION TO CRASH <----- : Private Function IPToText(ByVal IPAddress As String) As String : 'converts characters to numbers : IPToText = CStr(Asc(IPAddress)) & "." & _ : CStr(Asc(Mid$(IPAddress, 2, 1))) & "." & _ : CStr(Asc(Mid$(IPAddress, 3, 1))) & "." & _ : CStr(Asc(Mid$(IPAddress, 4, 1))) : End Function : ------------------------------------------------------------------------------------------------ : : Thanks : Abdullah
- Next message: Wally: "List of countries"
- Previous message: Abdullah Ali: "getting IP adress using hostname (IN CHINESE ENVIROMENT)"
- In reply to: Abdullah Ali: "getting IP adress using hostname (IN CHINESE ENVIROMENT)"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|
Loading