Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 12 of 12
  1. #1
    Regular Coder
    Join Date
    Nov 2002
    Posts
    180
    Thanks
    0
    Thanked 0 Times in 0 Posts

    how to get IP address

    i wana my computer to be server and another computer in remote place to be a client. after making my computer the server, how can i get its IP address to make the remote computer talk with it?
    i tried this but it worked only in the LAN:
    Code:
    import java.net.*; 
    public class LocalHostDemo {
    	public static void main(String args[]) {
    		System.out.println("Looking up local host"); 
    	    try {
    	    	InetAddress localAddress = InetAddress.getLocalHost(); 
    	    	System.out.println("IP address: " + localAddress.getHostAddress()); 
    	    }
    	    catch(UnknownHostException uhe) {
    	    	System.out.println("Error - unable to resolve localhost"); 
    	    }
    	 }
    }
    i mean the client was in the same LAN, but now i wana make the client in remote place.

  • #2
    Regular Coder
    Join Date
    Jan 2003
    Posts
    400
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You could get your IP adress simply by going to to www.whatismyip.com . If thats what your asking.. Not 2 sure what ur asking tho.

  • #3
    Regular Coder
    Join Date
    Nov 2002
    Posts
    180
    Thanks
    0
    Thanked 0 Times in 0 Posts
    how to get it using java?

  • #4
    Regular Coder
    Join Date
    Jan 2003
    Posts
    400
    Thanks
    0
    Thanked 0 Times in 0 Posts
    O, I am unfamiliar with java. However, you may find you answer here: http://mazsola.iit.uni-miskolc.hu/te...net/netcom.pdf

    I beleive you may find your answer around page 29.

  • #5
    Regular Coder
    Join Date
    Nov 2002
    Posts
    180
    Thanks
    0
    Thanked 0 Times in 0 Posts
    i tried www.whatismyip.com the ip address that i got it from isn't the same when i go to network properties in widows, and it was the same as another compuer in the same LAN. when i wana make a connection between two computers in a different LAN which ip should i use?

  • #6
    Regular Coder
    Join Date
    Nov 2002
    Posts
    180
    Thanks
    0
    Thanked 0 Times in 0 Posts
    or in other words i wana make connection between two computers, one of them is the client and the other one is the server, how can i do it with java or even c++?

  • #7
    Senior Coder Mhtml's Avatar
    Join Date
    Jun 2002
    Location
    Sydney, Australia
    Posts
    3,531
    Thanks
    0
    Thanked 1 Time in 1 Post
    Well you would use winsock in C++ .. assuming this is on windows.

    You would use gethostname() and then probably use gethostbyname() to resolve the ip... There is most likely a better way but I haven't really done much winsock stuff so that's how I'd do it.
    Omnis mico antequam dominus Spookster!

  • #8
    Regular Coder
    Join Date
    Nov 2002
    Posts
    180
    Thanks
    0
    Thanked 0 Times in 0 Posts
    actually the programming language is not the problem, what i wana know is how to make the connection, for example, in the network of our university there are many routers, if i wana connect to a computer outside this network, which IP should i give, and so on.

  • #9
    New Coder
    Join Date
    Apr 2004
    Location
    Texas
    Posts
    60
    Thanks
    0
    Thanked 0 Times in 0 Posts
    it sounds like your question is sort of a DNS question, Correct me if I'm wrong, you have 2 computers that connect on the same network, they can resolve one another, no problem all is well, but if you put client on a remote host, it can no longer resolve name of server. This is a DNS issue of sorts. Is the IP of your computer in network neighborhood something like 192.168.x.x ....if so this means it's a private IP address.

    you said
    "i tried www.whatismyip.com the ip address that i got it from isn't the same when i go to network properties in windows."

    This means you are probably using a either a proxy server or firewall or Network address translation of some kind....which complicates things...a lot.
    The IP shown on whatismyIP is probably that of your router/firewall, proxy server, or your NAT'd IP. One book I would recommend is Java Network Protocols Blackbook....it's niiiice for java network stuff, but the internet is the best resource......

    search and read, search and read, rinse and repeat.

    Sorry i don't have a quick answer for you, but a lot depends on how your network is setup....if there's a campus firewall like most universities have, then a remote client wouldn't be able to make a connection to a computer on the internal campus network at all most likely.....but what you could try is doing it the other way around. Run the server remotely, and the client locally for testing purposes. Your client could make the outbound connection. Check out gotdns.org for free dynamic dns service if needed....to give your remote server a 'NAME' that resolves from anywhere on the internet.

    hope this helped, but have a feeling it just gave you more questions.....there's a lot to it.......

    Regards,
    Jason B

  • #10
    Regular Coder
    Join Date
    Nov 2002
    Posts
    180
    Thanks
    0
    Thanked 0 Times in 0 Posts
    thanx alot black3842, i really appretiate your information, but till now i don't know how to make the connection through routers and firewalls , do u know any website for more information?

  • #11
    Regular Coder
    Join Date
    Jan 2003
    Posts
    400
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Okay, when you go to your windows command prompt, and you type up ipconfig (or something similar), you will get your network address. This may be something similar to 192.168.1.4 Usually it is only the last number that changes, depending on the router settings. Then, when you go to whatismyip.com, you will get your internet connection IP address. What happens when you get a connection in a lan, is kind of like a branch type system. First, you have your internet connection ---
    Then, your internet connection connects to a routere ---0
    Your router will then split that connection to multiple computers ---0<
    Your router will give all of the new computers a different IP adress, or a LAN address, different from the Internet Connection IP adress. If your computer is behind a router/LAN, and you would like for it to be directly accessed by the internet, you must edit your forwarding/DHCP settings. For example, if you have a Linksys router, you will have to go to the configuration page (usually 192.168.1.1), and on the top menu, click the advanced tab, then click the Forwarding Tab. On this page, you would enter the port and name that you would like your computer to be accessible by (Internet Port:80), then you also have to enter in your computers lan address. (The address you get from the microsoft command prompt: ipconfig)

    Does this help?

  • #12
    New Coder
    Join Date
    Nov 2003
    Location
    Northwest
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts

    try here

    http://java.sun.com/j2se/1.4/docs/api/index.html

    if u aint got the link already then u are gonna love me for givin it to you.

    this will give u all the standard classes and the construstors and methods in java. i know for a fact that there is a getIp() (not sure if that is what it is called in java) but it WILL be there somewhere!!

    Another way is to think Cookies!!! lots n lots n lots of ways of gettin IP address.

    ..Come find me in the Java Jungle...


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •