I programmatically (Azure, Java SDK) create Virtual Machine Scale Set ((Linux OS - Ubuntu) with ".withVirtualMachinePublicIp()" option during the creation. It works OK, I can see the instances and their public IP Addresses in the Azure Portal. I can ssh into the instances, etc... However I cannot get the public IP Addresses via Azure Java API, it always returns null. I tried a lot , the below code is just one of the attempts.
//vmss is a good working recently created instance off
//com.azure.resourcemanager.compute.models.VirtualMachineScaleSet class
for (VirtualMachineScaleSetNetworkInterface nis : vmss.listNetworkInterfaces())
{
String privip=nis.primaryPrivateIP();//works OK
Map<String, VirtualMachineScaleSetNicIpConfiguration> mp=nis.ipConfigurations();
for (Object key: mp.keySet())
{
VirtualMachineScaleSetNicIpConfiguration vip=mp.get(key);
String priva=vip.privateIpAddress();//works OK
String pipa=vip.innerModel().publicIpAddress().ipAddress();//always returns null
String pss=vip.innerModel().privateIpAddress();
System.out.println("PublicIP="+pipa+",PrivateIP="+priva+"="+pss);//Public IP is always null
}
}
I tried the above code but always receive null value as Public IP Address
I was helped on Git Hub. There is workaround:
https://github.com/Azure/azure-sdk-for-java/issues/33299#issuecomment-1415416429
Related
I have created a simple database application using rmi. It works fine with my local wireless network. But now i want to connect my client to the server through the internet. I know that, this can be achieved with setting up port forwarding in the router. But i want it to work in any computer which is connected to the internet using wifi connections, dialup
connections etc. How to do that?
what to write here? Naming.lookup ("rmi://?????????????");
As I am quite new to java, Please give me a detailed answer with a simple code example.
Thanks in advance
I hope you are messed up with Java RMI Concept. Irony is that a few days ago I was also thinking up the same except that I was thinking to connect up on my internal network.
There are two kinds of classes that can be used in Java RMI.
A Remote class is one whose instances can be used remotely. An object
of such a class can be referenced in two different ways:
1. Within the address space where the object was constructed, the object is an ordinary object which can be used like any other object.
2. Within other address spaces, the object can be referenced using an object handle. While there are limitations on how one can use an
object handle compared to an object, for the most part one can use
object handles in the same way as an ordinary object.
A Serializable class is one whose instances can be copied from one
address space to another. An instance of a Serializable class will be
called a serializable object. In other words, a serializable object is
one that can be marshaled.
SO, HERE COMES THE ANSWER TO YOUR QUESTION,ASSUMING YOU ARE TALKING ABOUT REMOTE CLASS ON DIFFERENT SYSTEM(SERVER).
The name of a remote object includes the following information:
The Internet name (or address) of the machine that is running the
Object Registry with which the remote object is being registered. If
the Object Registry is running on the same machine as the one that is
making the request, then the name of the machine can be omitted.
The port to which the Object Registry is listening. If the Object
Registry is listening to the default port, 1099, then this does not
have to be included in the name.
The local name of the remote object within the Object Registry.
The URL for a remote object is specified using the usual host, port and name:
rmi://host:port/name
host = host name of registry (defaults to current host)
port = port number of registry (defaults to the registry port number)
name = name for remote object
Assuming that your code is lying on the server having host-name as "XYZ.edu/home/CLasses"(you can give the DNS/IP-Address of server and include the location of the Class file),port-number="1099"(default) and name of the remote Object="abc" for your ABC.java Class in Server. In this way one will be able to call the Remote Object from different machines. Also, you need to keep the whole Server code on the Internet Address so that Clients can access them from the Internet(one can't access the offline-code present in your machine). Then only it can happen!!!
Here is the example Client program:
/**
* Client program for the "Hello, world!" example.
* #param argv The command line arguments which are ignored.
*/
public static void main (String[] argv) {
try {
HelloInterface hello =
(HelloInterface) Naming.lookup ("//ortles.ccs.neu.edu/Hello"); //see here the address of the server hosting the Server file,you can omit port number,it'll take default port 1099.
System.out.println (hello.say());
} catch (Exception e) {
System.out.println ("HelloClient exception: " + e);
}
}
Is there any way to get MAC address of elastic network interface of aws, using aws JAVA SDk
I could get the MAC address using AWS-CLI using describe-network-interfaces command as below:
$ aws ec2 describe-network-interfaces --network-interface-ids eni-eaxxxxd | jq ".NetworkInterfaces[].MacAddress"
"06:56:88:b9:82:17"
ALso in Ruby-SDK, there is a way to pull the MAC address using describe_network_interfaces-instance_method
I searched the JAVA SDK documentation for DescribeNetworkInterfacesRequest and seems it does provides mac address. However, I am not good at reading JAVA API Documentation.
As I was able to get the MAC address using AWS-CLI and RUBY-SDK, the API is in place. Just that you need to get the exact method in JAVA-SDK documentation.
// get network interface of instance and from that get mac address
List<InstanceNetworkInterface> networkInterfaces = inst.getNetworkInterfaces();
for (InstanceNetworkInterface instanceNetworkInterface : networkInterfaces) {
System.out.println("=-------------"+instanceNetworkInterface.getNetworkInterfaceId());
DescribeNetworkInterfacesRequest describeNetworkInterfacesRequest = new DescribeNetworkInterfacesRequest();
describeNetworkInterfacesRequest.withNetworkInterfaceIds(instanceNetworkInterface.getNetworkInterfaceId());
DescribeNetworkInterfacesResult describeNetworkInterfacesResult = amazonEc2.describeNetworkInterfaces(describeNetworkInterfacesRequest);
List<NetworkInterface> networkInterfaces1 = describeNetworkInterfacesResult.getNetworkInterfaces();
for (NetworkInterface networkInterface : networkInterfaces1) {
System.out.println(networkInterface.getMacAddress());
}
}
//-------------------------
I have a server-side application written in Java.
We use Jetty to provide our servlets.
Final users use the browser to 'use' our app.
From a server-side point of view when I get an HttpServletRequest is it possible to know if it from a browser which is running on the same machine that the server has been installed on?
(that being the case I am obviously testing and I would like to do something about it)
You can use ServletRequest.getRemoteHost() which returns the fully qualified name of the client that sent the request and compare it to local host name InetAddress.getLocalHost().getCanonicalHostName()
I guess you can check whether the ip address of the request is the same as server's or if it's coming from localhost?
I guess this can help:
String getRemoteIP(HttpServletRequest request) {
String xff = request.getHeader("X-Forwarded-For");
if (xff != null) {
return xff.split("[\\s,]+")[0];
}
return request.getRemoteAddr();
}
Compare this address to server's.
I took this code from here
I have this function to get the HostAddress from my request (HttpServletRequest) on Java. But using Jetty 7.x and my IP is ipV6 I have always this error with iPv6 address.
My function:
xxxx.getIP(request, false);
public static String getIP(HttpServletRequest request, boolean proxy) {
String ip = "";
log.debug("X-getHeaderNames ["+ request.getHeaderNames()+"]");
if (proxy) {
ip = XFordwardedInetAddressUtil.getAddressFromRequest(request);
} else {
String _ip = request.getRemoteAddr();
ip = InetAddresses.forString(_ip).getHostAddress();
}
return ip;
}
The error:
DEBUG: org.encuestame.core.exception.EnMeMappingExceptionResolver - Resolving exception from handler [org.encuestame.mvc.controller.TweetPollController#4fc23996]: java.lang.IllegalArgumentException: '0:0:0:0:0:0:0:1%0' is not an IP string literal.
java.lang.IllegalArgumentException: '0:0:0:0:0:0:0:1%0' is not an IP string literal.
at org.encuestame.utils.net.InetAddresses.forString(InetAddresses.java:59)
at org.encuestame.core.util.EnMeUtils.getIP(EnMeUtils.java:210)
at org.encuestame.mvc.controller.AbstractBaseOperations.getIpClient(AbstractBaseOperations.java:262)
at org.encuestame.mvc.controller.TweetPollController.detailTweetPollController(TweetPollController.java:332)
at org.encuestame.mvc.controller.TweetPollController$$FastClassByCGLIB$$6990b004.invoke()
at net.sf.cglib.proxy.MethodProxy.invoke(MethodProxy.java:191)
at org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedIntercepto
I know the iPv6 localhost format should be '0:0:0:0:0:0:0:1' but my request always return this string '0:0:0:0:0:0:0:1%0'
Anyone can help me?
The problem is that the class you're using (org.encuestame.utils.net.InetAddresses) clearly doesn't support IPv6. Try using the java InetAddress class that Joachim mentioned in his answer.
When you're using a link local address, the % should be included in the address.
This is due to the fact that the computer needs to know which interface/zone the request came from to be able to reply out the correct interface.
If you're using correctly configured, Internet routable IPv6 addresses, the zone index will not be a part of the address.
In this case, I can't see a way to solve your problem for localhost/link local testing except to filter out anything after the % sign, or use another class that works with link local addresses to parse the address.
EDIT: Here's another - similar - question I didn't see earlier.
I'm programming a simple web browser depending on NanoHTTPD project and it's required to get number of visitors using the IP address.
Are there any ways to get the client IP using NanoHTTPD?
In NanoHTTPD.java, find the private class HTTPSession object.
Inside this is public void run(). Find the following line and add the second line after it.
decodeHeader(hin, pre, parms, header);
header.put("IPAddress", mySocket.getInetAddress().getHostAddress());
Now inside your serve function, you can just reference the IPAddress header to get the client's ip address.
I know the answer is probably too late to help you, but hopefully it'll help others searching for the same thing.
I found in the latest master branch, you can get the client ip address by header "http-client-ip" in the IHTTPSession session object.