Overclock.net - Overclocking.net
     
 
Home Gallery Reviews Blogs Register Today's Posts Mark Forums Read Members List


Go Back   Overclock.net - Overclocking.net > Software, Programming and Coding > Coding and Programming

Reply
 
LinkBack Thread Tools
Old 05-19-08   #1 (permalink)
Programmer
 
LyokoHaCk's Avatar
 
amd nvidia

Join Date: Aug 2006
Location: United States Inc.
Posts: 1,959

Rep: 73 LyokoHaCk is acknowledged by some
Unique Rep: 68
FAQs Submitted: 1
Trader Rating: 2
Default [VB.Net to Java] Function Conversion

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.

Last edited by LyokoHaCk : 05-20-08 at 04:54 PM.
LyokoHaCk is offline   Reply With Quote
Old 05-20-08   #2 (permalink)
Programmer
 
LyokoHaCk's Avatar
 
amd nvidia

Join Date: Aug 2006
Location: United States Inc.
Posts: 1,959

Rep: 73 LyokoHaCk is acknowledged by some
Unique Rep: 68
FAQs Submitted: 1
Trader Rating: 2
Default

Bump
LyokoHaCk is offline   Reply With Quote
Old 05-20-08   #3 (permalink)
Mmmm! Toast!
 
hometoast's Avatar
 
intel nvidia

Join Date: Sep 2007
Location: Pennsylvania
Posts: 919

Rep: 69 hometoast is acknowledged by some
Unique Rep: 55
Trader Rating: 8
Default

this might be helpful
http://exampledepot.com/egs/java.net...IP%20Addresses
__________________
Rocket 3 down-payment fund: [|||||||||] $6k
e6750 @ 3.2 Ghz (400x8)

System: Muh Box
CPU
E6750 @ 3.2Ghz
Motherboard
DFI Blood Iron
Memory
4x1G GSkill HZs @960
Graphics Card
eVGA 8800GT 512 @675/950
Hard Drive
2xWD 320 AAKS Raid0 + 74G Raptor
Sound Card
X-Fi XtremeMusic
Power Supply
CM Extreme Power 650W
Case
CM Centurion 5
CPU cooling
AC Freezer 7
OS
Vista Biz 64
Monitor
Samsung 204BW
hometoast is offline Overclocked Account   Reply With Quote
Old 05-21-08   #4 (permalink)
Kernel Sanders
 
rabidgnome229's Avatar
 
intel nvidia

Join Date: Feb 2006
Location: Pittsburgh
Posts: 4,894
Blog Entries: 1

Rep: 548 rabidgnome229 is becoming famousrabidgnome229 is becoming famousrabidgnome229 is becoming famousrabidgnome229 is becoming famousrabidgnome229 is becoming famousrabidgnome229 is becoming famous
Unique Rep: 326
FAQs Submitted: 6
Trader Rating: 5
Default

Quote:
Originally Posted by LyokoHaCk View Post
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
__________________
BIG BROTHER
I put on my robe and wizard hat...

IS WATCHING

System: It goes to eleven
CPU
E6300
Motherboard
DS3
Memory
2GB XMS2 DDR2-800
Graphics Card
EVGA 8600GTS
Hard Drive
1.294 TB
Sound Card
Audigy 2 ZS
Power Supply
Corsair 520HX
Case
Lian-Li v1000B Plus
CPU cooling
TTBT
GPU cooling
Thermalright V2
OS
Arch Linux/XP
Monitor
Samsung 226bw
rabidgnome229 is offline Overclocked Account   Reply With Quote
Old 05-21-08   #5 (permalink)
Programmer
 
LyokoHaCk's Avatar
 
amd nvidia

Join Date: Aug 2006
Location: United States Inc.
Posts: 1,959

Rep: 73 LyokoHaCk is acknowledged by some
Unique Rep: 68
FAQs Submitted: 1
Trader Rating: 2
Default

Thank you both. Repped!
LyokoHaCk is offline   Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools



All times are GMT -4. The time now is 08:32 PM.


Overclock.net is a Carbon Neutral Site Creative Commons License Internet Security By ControlScan

Terms of Service / Forum Rules | Privacy Policy | Advertising | Become an Official Vendor
Copyright © 2008 Shogun Interactive Development. Most rights reserved.
Page generated in 0.13877 seconds with 9 queries