Use VPN ip address htttp Urlconnection java - java

I have openVPN Connect configured on a vista laptop, so that connecting with a web browser allows the computer to change its ip address. What are the steps necessary to allow the following networking code in java to use this new ip address:
HttpURLConnection x=(HttpURLConnection)new URL("google.com/search?sclient=psy-
ab&h1=en&site=&source=hp&q=ip%20address&btnG=Search").openConnection();
And then open an input stream, read it in, and see one of the vpn addresses in the page, after the html: "Your public IP address is "

You can't without calling to an external service.
You will need to have your application call something like http://www.whatismyip.com/ and parse out the IP address the wider internet sees you as. There is probably a REST service you can call which gives you the answer back as XML/JSON/something more computer parseable.
Unfortunately, your local machine does not have enough information for Java to be able to find out without going external.

Related

Need to access API (https://localhost:8080/er/heartbeats) from another VM

I am working on task where I need to access URL https://localhost:8080/er/heartbeat which gave data from heartbeat.xml from other VM.
Need help in this.
You cannot access "localhost" (127.0.0.1, etc) from another machine. The 127.x.x.x net range is for host-local use only. The packets sent to this range are not (should not be) routed outside of this machine / virtual machine.
You need to use an external IP address for this machine or a DNS name that resolves to an external IP address. (It could be a private IP address, provided that the other VM knows how to route packets to it.)
References:
How to view the localhost of another computer in the same network?
The Wikipedia page on localhost.
If you are in the same network you just need to know the IP of your machine and access it like:
https://other.machine.ip:8080/er/heartbeat

Which ip address should I use to connect 2 computers in my home using datagram sockets in java?

I am trying to connect 2 computer in my home using DatagramSockets (or even Sockets) in java. What exactly should I do? Which IP Address should I use to connect them?
If your machine is using DHCP then it's not upto you to decide which ip address you will use. Your machine will be assigned some dynamic ip address. To see that use ifconfig on Linux box and ipconfig on win machine. Once you have their IP address you can use these to connect your machine. Chances are high that your machine has dynamic ip's.
Assuming you're a windows user:
to get your LAN IP address open a command prompt and type ipconfig.
A bunch of stuff will show up, you are looking for the line that says
IPv4 address.....: 192.168.#.#
It should be noted however, that this is a so "dynamic" ip address, that can be changed whenever you disconnect and reconnect from your router.
I recommend that you either make your ip static (look this up on google, there are lots of tutorials) or use your computers hostname instead. To obtain your hostname you simply type hostname in the commandprompt.
in your code you can get your ip address by doing this in your client code:
String ip = Inet4Address.getByName("<your servers hostname>").getHostAddress();
I hope this helps, although questions like these belong on Super User, as they really don't have much to do with coding.

Internet of Things : ESP module Wifi Ip address

as you can read in title I'm making a super simple IOT (Not really)
and
using a esp8266 and want to make it connect to my home wifi network and make a communication between a android app and the module (android app connects to home wifi)
Note : Iam Using CODE VISION AVR
you may say :
Why not directly connect to ESP when its on Server Mode?
that's fine cause when ESP is server "he" can set ip for him self so
ip will be always same BUT I want it to connect to home wifi
-
Why you wont connect with IP ?
you cant find the module ip easily because its given by Wifi
-
Find ESP ip using IP scanner
Its not possible cause it changes every time and user have to change
IP every time in android app AND my app cant scann every time it want
to connect to a single device its so dumb...
-
Do a Static Ip for ESP !
well that's not possible too because maybe that IP was taken by
someone before ESP send static IP AT command ! + if IP wasent taken it may taken after Home Wifi Restarts !
Sorry for bad English :X
You can use software serial to configure esp8266 from arduino. You need to know the setup circuit perfectly. Keep it in mind that esp8266 operates on 3.3V where arduino gives 5V output. The most important thing is to send AT commands to esp8266. You can use the following command to connect with your wifi.
AT+CWJAP="Your_WiFi","password"
If you need to see the ip address of esp8266, you can use this command.
AT+CIFSR
If you want to set static ip to esp8266 , then you can try this one.
AT+CIPSTA="ip module","ip gateway","subnet mask"
Use mDNS responder:
https://github.com/esp8266/Arduino/blob/master/libraries/ESP8266mDNS/examples/mDNS_Web_Server/mDNS_Web_Server.ino
This way you would be able to connect to ESP8266 via hardcoded url like http://esp8266.local.

Multiple Socket IP address debugging on same machine

I'm designing a chat service that uses Java server sockets.
When a user connects to my server with their browser I need to make sure their connection information stays the same when they open new pages on my site in their browser. So I need to keep track of their remote IP address. I am using this below, but am unable to test it as I am on a local machine.
client.socket.getRemoteSocketAddress()
I want to test my system with multiple IP address from the client conenctions but I can not do so since this method above returns the same IP as I am local. How can I go about debugging and testing such a setup in Eclipse?
You could assign multiple addresses to a single NIC in Windows' Network properties->advance option.
Check out short tutorial:
http://www.tutorialspoint.com/shorttutorials/assign-multiple-ip-addresses-to-windows-8-computer
Also, you most like have to bind the address manually,
i.e. client.bind("some ip");

Whats my hostname on my local MySQL server?

I just set up a MySQL server on my PC for testing Java with JDBC.
At the moment "localhost" works perfectly as hostname for my applications, when running them on the same system.
However what would be the hostname for my MySQL server for applications that are running on different computers? Something like "my_ip:port" would work? I was thinking of writing an applet, which I could upload on a web server and try to connect to my database here. Is it possible to achieve that?
Something like "my_ip:port" would work?
If the MySQL instance has bound to your public interface, and if your firewall allows it, yes. If you connect to the 'net via a router that does NAT (for instance, a combined DSL modem and wireless router allowing you to connect multiple computers), you'll have to set up forwarding rules in the router to tell it which of the local machines to forward requests to.
You don't have to use an IP address. Your machine will also probably have a host name of some kind (either one you've assigned or, if you connect through an ISP, more likely one they've assigned). That would work too.
I was thinking of writing an applet, which I could upload on a web server and try to connect to my database here. Is it possible to achieve that?
With a signed Java applet, yes; otherwise, no. That's because the security sandbox that Java applets run in doesn't let them access servers other than the one they were loaded from (the web server).
A much better approach is to have your client-side code (Java applet, or just DHTML+Ajax stuff) talk to server-side code on the web server, which in turn talks to your DB. That way, the DB is never directly exposed to the outside world, and you don't have to do things like signed applets.
You can always use the ip address of the server running mysql as the hostname or its fully qualified domain name.
That should work, but you also should consider port-forwarding through your firewall.
Go here to get your IP: http://www.whatsmyip.org/
The port is the port mysql is setup on.

Categories