How do i get the dynamic IP address assigned by the ISP for a Dialup connection using java?
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Harsh_Bhattachar
Posted On:   Tuesday, February 12, 2002 10:57 PM

I have a Dialup connection with a Ethernet Lan card . When I have dialed up and connected to the Internet I need to know what IP address is assigned to me by the ISP. Please if anyone could help me out on this.
Thanks and have a nice day.....

Re: How do i get the dynamic IP address assigned by the ISP for a Dialup connection using java?

Posted By:   James_Collett  
Posted On:   Wednesday, February 13, 2002 07:04 AM

To get your IP from within Java, use this:

import java.net.*;
import java.io.*;

public class MyIP {
public static void main(String args[]) {
String ip = new MyIP().myIP();
System.out.println(ip);
}

public String myIP() {
try {
return InetAddress.getLocalHost().getHostAddress();
}
catch (IOException e) {
return "unknown";
}
}
}
About | Sitemap | Contact