Quote:
Originally Posted by LyokoHaCk
Code:
Public Shared Function GetCIP(ByVal name As String) As String()
Dim list As ArrayList
Dim IP As IPAddress
Try
list = New ArrayList
For Each IP In Dns.GetHostAddresses(name)
list.Add(IP.ToString)
Next
Return CType(list.ToArray(GetType(String)), String())
Catch ex As Exception
Debug.WriteLine(ex)
Return New String() {}
End Try
End Function
A) What exactly does this do?
B) How can I replicate this in Java? There is no IP type in Java as far as I know. Thanks.
|
It iterates through all IP's that a call to Dns.GetHostAddresses with the function's argument as an argument. For each IP address it converts it to a string and stores it in an arraylist. If it is successful it returns the array representation of the arraylist. If an exception occurs it returns an empty string array. I don't know what the Java equivalent of Dns.GetHostAddresses is, but here's the rest of the code in java
Code:
public String[] GetCIP(String name){
ArrayList<String> list;
ListIterator it;
try{
list = new ArrayList<String>();
it = Dns.GetHostAddresses(name).iterator();
while(it.hasNext)
list.add(it.next().toString());
return list.toArray();
}catch(Exception e){
return new String[0];
}
}
In the code I assume that Dns.GetHostAddresses(String) returns a list of some kind. You will have to replace this with its java equivalent because I don't know what it is. If it doesn't return a list the code will have to change somewhat.
It's been a while since I used java but the above should work