IP Address: using program or script - ip

A) The below statement
System.out.println(java.net.Inet4Address.getLocalHost());
shows output as myhostname/192.168.1.25
B) The http://whatismyipaddress.com/ shows below (masked):
14x.7x.2xx.x1x
Using above mentioned technique A (any language or script), how do I get the value 14x.7x.2xx.x1x that above mentioned technique B shows? Or, is it at all possible?
In other words (?), using technique A (as mentioned in original question), how I can I get the same public Ip address of my home router which is shown by technique B? If it is impossible, please explain briefly (two lines at the most) why?
Thanks

Refer to this question:Getting the 'external' IP address in Java
The computer don't know its final public address as it is not necessary for it to know. Local network IP Address is sufficient for it for the tasks. But if you want to get the public address you have to use an external service as mentions in the answers of the linked question.

I will assume that you are at your home and you have a router for connecting your several computers to the internet.
http://whatismyipaddress.com/ will show an IP address as it is visible on the global internet. This may well be the IP address of your in-home router, which exposes one address for your entire in-home network. This is your public IP address.
The script that you show will give you the IP address of your own machine, which is usually only useful on your own local network. This is a private IP address, only accessible from your local network.

Related

Why is my IP adress different when displayed by different methods

I am new to all this, so I am sorry if the question is stupid. I am learning about networking and I want to find out IP address of my own computer.
When I try to display it through ipconfig, my router's configuration page and by simply googling, I see different IP-address
Thank you in advance for help
in ip-config it starts with 10. ...
in router's conf page 192.168.1. ...
when googling 213. ...
ipconfig will give you the address of your machine. This will be some private IP address. Your router will have two IP address - One public and one private. All machines in your local network (house probably) will talk to the router via its private address, while everything out in the Internet talk to your router via its public address.
So, ipconfig provides the address of your computer, your router's config page shows its private address, and Google will show you your router's public address.
Some terms to look up: Look up Public vs Private IP addresses and how NAT works and this will all make more sense.

Why does my IP address Change so frequently?

I have connected my network connection through the wireless device with DHCP. Recently I have changed my connection from wireless to wired cable connection.
At that time My IP address got changed automatically,
I tried these steps Changing Your Private IP to have my past IP address but also it changes automatically.
Now, when I check my IP address it shows a different IP from before. That makes 3 changes, my confusion is around whether it changes itself once per day or not. If anyone has an answer for this, please let me know.
Are you sure you talk about private IP and not Public one ?
Did you try going back to wireless for few days and watch if your private IP don't change ?
Some details are missing so I can't probably make a good diagnosis of what you have here. But for now I'll try to help out.
If you are talking about your public IP address it's normal that it'll get changed quite often, unless you have signed up on your ISP for a static public IP address (ex. you told you're ISP that you'll be running a web server). It's normal for the IP to change in intervals, days, hours or even minutes if your ISP has lots of users.
If you're talking about your local IP address, you should check your router out (assuming you use one), check if how many people are using/connected to it.
OK, so we're dealing with Private IP. Your problem is it changing whenever you Disconnect/Connect right? Are you the only user? Or are you suspecting the router might be spewing out random IPs from the IP pool even if the previous ones aren't already allocated?
Ex.
a) You connect, router gives you 192.168.0.2
b) You disconnect
c) Some other PC connects and gives 192.168.0.2
d) You connect again and router gives you 192.168.0.3
Are you talking something like the above situation?
EDIT: Silly me, found out that I can comment on my own answer.

Does the idea of private ip address in ipv6?

For the idea of private, I mean it like 10.*.*.* idea of ipv4. It seems ipv6 don't conserve ip addresses like these any more.
So, what if I want to create a private subnet which I don't want the others to know my subnet number or access my subnet with ip address. I can create my own range of ip subnet number, but it seems in that way, it would conflicts with global ip address.
I know the idea of link local address, but I think that's useless when I want several links to constitute a network.
If you are just setting up a private local network for development/testing and don't have any actual IPv6 connectivity of your own (or your ISP is stupid and only gave you a /64) then unique local addresses will work fine for you.
However, unique local addresses cannot be used for connectivity to the global Internet. If you need this, you should get global addresses and a proper firewall (as NAT is not needed and strongly discouraged in IPv6).
To get a /48 ULA prefix, visit this generator and throw in a MAC address. (Using a MAC address to generate the prefix is specified by RFC 4193, which defines unique local addresses.)

IP Changing Program

So, my work has several networks and small business locations all with an internet blocking server. The managers all rotate and want freedom from the server, AKA static IP addresses outside the range of DHCP.
my problem is that they all need access to each others network, so setting up an alternate configuration is not that useful. How would I create an application that will change my users IP Address so that it will match their static IP at the location they changed it too?
This is just their internal IP address on their local machine, and each location's network has a static ip waiting for them. Just have to change their IP Address.
Is there a batch file command that can help achieve this? if not maybe writing a script or going into a larger application?
Doing this on the machine itself will be difficult. It needs to be able to recognise each network, and what will it do when connecting to an unknown network like a home network or a hotspot?
I think it would be better to let the DHCP server hand out static addresses from outside the normal dynamic address pool. That way everything keeps working automatically while also giving static addresses to the machines.
I know this is not a real answer to your question, but I hope this gives you an alternative.

Access localhost from another computer not on network

Before you say that it is a dupe, this is not the same as this, this, this or this.
My question is how do you do it globally.
For instance, consider this. I have EasyPHP running in my computer. At present my ip address (global) is 223.231.178.118
Now, let's say there is someone else (maybe in a different country altogether) who wants to access my ip (223.231.178.118). I do know how to access 192.168.x.x from the same network. I just want to know how you can do this globally, if possible.
P.S 1 : The computer running EasyPHP is behind a router.
P.S 2 : My IP (local IP is, but global one is not) is not static. But let us assume the person who wants to access my localhost does know my Dynamic IP. For example, let us assume I tell the person who wants to access my localhost is my friend and I tell him over phone what my IP is.
You can use tools just like ngrok or Forward
more tools are in this post Accessing localhost From Anywhere
Your local IP address "192.168.x.x" is only known to your router and unknown to everyone outside your LAN. The global IP address (223.231.178.118 in your example) is the global address of your router.
To be able to access the EasyPHP server on your local computer you need to forward the corresponding port (for http webservers the default is 80 but it might be different for EasyPHP) from your router to your local IP. You need to check your routers manual on how to do this.
After you have done that you can just tell the person who wants to access your local computer the global ip address of your router and he will see your EasyPHP response by browsing to that global address.

Resources