I want to fetch default gateway for local machine using java. I know how to get it by executing dos or shell commands, but is there any another way to fetch?
Also need to fetch primary and secondary dns ip.
My way is:
try(DatagramSocket s=new DatagramSocket())
{
s.connect(InetAddress.getByAddress(new byte[]{1,1,1,1}), 0);
return NetworkInterface.getByInetAddress(s.getLocalAddress()).getHardwareAddress();
}
Because of using datagram (UDP), it isn't connecting anywhere, so port number may be meaningless and remote address (1.1.1.1) needn't be reachable, just routable.
In Windows with the help of ipconfig:
import java.awt.Desktop;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URI;
public final class Router {
private static final String DEFAULT_GATEWAY = "Default Gateway";
private Router() {
}
public static void main(String[] args) {
if (Desktop.isDesktopSupported()) {
try {
Process process = Runtime.getRuntime().exec("ipconfig");
try (BufferedReader bufferedReader = new BufferedReader(
new InputStreamReader(process.getInputStream()))) {
String line;
while ((line = bufferedReader.readLine()) != null) {
if (line.trim().startsWith(DEFAULT_GATEWAY)) {
String ipAddress = line.substring(line.indexOf(":") + 1).trim(),
routerURL = String.format("http://%s", ipAddress);
// opening router setup in browser
Desktop.getDesktop().browse(new URI(routerURL));
}
System.out.println(line);
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
Here I'm getting the default gateway IP address of my router, and opening it in a browser to see my router's setup page.
There is not an easy way to do this. You'll have to call local system commands and parse the output, or read configuration files or the registry. There is no platform independent way that I'm aware of to make this work - you'll have to code for linux, mac and windows if you want to run on all of them.
See How can I determine the IP of my router/gateway in Java?
That covers the gateway, and you could use ifconfig or ipconfig as well to get this. For DNS info, you'll have to call a different system command such as ipconfig on Windows or parse /etc/resolv.conf on Linux or mac.
There is currently no standard interface in Java to obtain the default gateway or the DNS server addresses. You will need a shell command.
I'm not sure if it works on every system but at least here I found this:
import java.net.InetAddress;
import java.net.UnknownHostException;
public class Main
{
public static void main(String[] args)
{
try
{
//Variables to find out the Default Gateway IP(s)
String canonicalHostName = InetAddress.getLocalHost().getCanonicalHostName();
String hostName = InetAddress.getLocalHost().getHostName();
//"subtract" the hostName from the canonicalHostName, +1 due to the "." in there
String defaultGatewayLeftover = canonicalHostName.substring(hostName.length() + 1);
//Info printouts
System.out.println("Info:\nCanonical Host Name: " + canonicalHostName + "\nHost Name: " + hostName + "\nDefault Gateway Leftover: " + defaultGatewayLeftover + "\n");
System.out.println("Default Gateway Addresses:\n" + printAddresses(InetAddress.getAllByName(defaultGatewayLeftover)));
} catch (UnknownHostException e)
{
e.printStackTrace();
}
}
//simple combined string out the address array
private static String printAddresses(InetAddress[] allByName)
{
if (allByName.length == 0)
{
return "";
} else
{
String str = "";
int i = 0;
while (i < allByName.length - 1)
{
str += allByName[i] + "\n";
i++;
}
return str + allByName[i];
}
}
}
For me this produces:
Info:
Canonical Host Name: PCK4D-PC.speedport.ip
Host Name: PCK4D-PC
Default Gateway Leftover: speedport.ip
Default Gateway Addresses:
speedport.ip/192.168.2.1
speedport.ip/fe80:0:0:0:0:0:0:1%12
Related
import java.net.ServerSocket;
import java.net.Socket;
import java.io.IOException;
import java.io.OutputStream;
import java.io.InputStream;
public class ChatClient{
private final String serverName;
private final int serverPort;
private Socket socket;
private InputStream serverIn;
private OutputStream serverOut;
public ChatClient(String serverName, int serverPort) {
this.serverName = serverName;
this.serverPort = serverPort;
}
public static void main(String[] args){
ChatClient client = new ChatClient("raspberrypi", 6342);
if (!client.connect()){
System.err.println("Connect failed");
}else{
System.out.println("Connected");
}
}
private boolean connect(){
try{
this.socket = new Socket("raspberrypi", 6342);
this.serverOut = socket.getOutputStream();
this.serverIn = socket.getInputStream();
return true;
}catch (IOException e){
e.printStackTrace();
}
return false;
}
}
I have a server which I am running which is waiting for an client to join. However since I am using the client on my computer and the server on my raspberry pi, I keep getting the unknown host exception. I have tried to put the hostname of the raspberry pi in but it doesn't seem to work. P.s I might be getting the host name wrong.
It does not work, because the value you provide to the first argument (raspberrypi) is not a valid host name.
You need to pass there the IP address of your raspberry in your network.
If you are using home router, you can even set static IP for your raspberry (it's common, because without that, every time you restart your raspberry, you may get different address from DHCP server).
After you know the address of your raspberry, simply replace "raspberrypi" with the address (in form of "192.168.0.10" depending on your configuration).
Here's how to set static IP: https://www.raspberrypi.org/learning/networking-lessons/rpi-static-ip-address/
Edit the file /etc/dhcpcd.conf as follows:
Type sudo nano /etc/dhcpcd.conf at the command prompt.
Scroll to the bottom of the script, and add the following lines:
interface eth0
static ip_address=192.168.0.2/24 static routers=192.168.0.1 static
domain_name_servers=192.168.0.1
interface wlan0
static ip_address=192.168.0.2/24 static routers=192.168.0.1 static
domain_name_servers=192.168.0.1
Save the file with ctrl + o and then
exit nano with ctrl + x. Your Raspberry Pi will now boot up with the
IP address 192.168.0.2 every time; we didn't use 192.168.0.1 as this
is reserved for the router. You can of course use any address you
like, but in the configuration above the range must be between
192.168.0.2 and 192.168.0.255.
I am trying to run my server named SampleServer. I am using windows and this is what i did:
in cmd:
javaw rmiregistry 1099
cd C:\Users\Home\workspace\RMI\src
java -Djava.security.policy=policy SampleServer 1099
i get the following error:
binding //localhost:1099/Sample
New instance of Sample created
Sample server failed:Connection refused to host: localhost; nested exception is:
java.net.ConnectException: Connection refused: connect
I've tried using a different port # such as 4719 for rmiregistry but i receive the same error. I made sure that my firewall was disabled but the problem persist. I made sure that the port is not already being used. I really hope someone can help me.
Picture of my desktop with folders of project, eclipse window and cmd open:
http://s22.postimg.org/uq00qzslr/picyture.png
Code:
SampleServer:
import java.rmi.Naming;
import java.rmi.RemoteException;
import java.rmi.RMISecurityManager;
import java.rmi.server.UnicastRemoteObject;
public class SampleServer {
public static void main(String args[]) {
if (args.length != 1) {
System.err.println("usage: java SampleServer rmi_port");
System.exit(1);
}
// Create and install a security manager
if (System.getSecurityManager() == null)
System.setSecurityManager(new RMISecurityManager());
try {
// first command-line argument is the port of the rmiregistry
int port = Integer.parseInt(args[0]);
String url = "//localhost:" + port + "/Sample";
System.out.println("binding " + url);
Naming.rebind(url, new Sample());
// Naming.rebind("Sample", new Sample());
System.out.println("server " + url + " is running...");
}
catch (Exception e) {
System.out.println("Sample server failed:" + e.getMessage());
}
}
}
SampleClient:
import java.rmi.Naming;
import java.rmi.RemoteException;
public class SampleClient {
public static void main(String args[]) {
try {
if (args.length < 3) {
System.err.println("usage: java SampleClient host port string... \n");
System.exit(1);
}
int port = Integer.parseInt(args[1]);
String url = "//" + args[0] + ":" + port + "/Sample";
System.out.println("looking up " + url);
SampleInterface sample = (SampleInterface)Naming.lookup(url);
// args[2] onward are the strings we want to reverse
for (int i=2; i < args.length; ++i)
// call the remote method and print the return
System.out.println(sample.invert(args[i]));
} catch(Exception e) {
System.out.println("SampleClient exception: " + e);
}
}
}
SampleInterface:
import java.rmi.Remote;
import java.rmi.RemoteException;
public interface SampleInterface extends Remote {
public String invert(String msg) throws RemoteException;
}
Sample:
import java.rmi.Remote;
import java.rmi.RemoteException;
import java.rmi.server.*;
// this is the class with remote methods
public class Sample
extends UnicastRemoteObject
implements SampleInterface {
private int a;
public Sample() throws RemoteException {
System.out.println("New instance of Sample created");
a = 1;
}
public String invert(String m) throws RemoteException {
// return input message with characters reversed
System.out.println("invert("+m+") a=" + a);
return new StringBuffer(m).reverse().toString();
}
}
policy:
grant {
permission java.security.AllPermission;
};
javaw rmiregistry 1099
Stop right there. This is already wrong. 'rmiregistry' is an executable, not the name of a Java class you can execute with 'java' or 'javaw'. Just use 'rmiregistry'.
This error occurs when there is no service running on the port, you are trying to connect. As said by EJP, rmiregistry is a tool which can be started by rmiregistry & in the background (JDK 7). I would recommend you that you check your firewall or connectivity issue with the port.
Greetings!
I am trying to find a way in Java to programmatically enable/disable a port on a network switch over SNMP. I tried using SNMP4J but couldn't get much help on the mailing list on how to use it. I'm not too concerned what library is used (open source vs commercial) as long as it gets the job done.
The switch I am trying to work with is a Cisco 3750 switch.
Regards,
James
You can use following simple code to enable/disable switch port using snmp4j.
It enables port 1 and disables port 6.
package com.mobinet.snmp;
import org.snmp4j.CommunityTarget;
import org.snmp4j.PDU;
import org.snmp4j.Snmp;
import org.snmp4j.TransportMapping;
import org.snmp4j.event.ResponseEvent;
import org.snmp4j.mp.SnmpConstants;
import org.snmp4j.smi.Address;
import org.snmp4j.smi.GenericAddress;
import org.snmp4j.smi.Integer32;
import org.snmp4j.smi.OID;
import org.snmp4j.smi.OctetString;
import org.snmp4j.smi.VariableBinding;
import org.snmp4j.transport.DefaultTcpTransportMapping;
/**
*
* #author batbayar
*/
public class SnmpTest {
private String address = "192.168.1.254/161"; // switch address and snmp port
private String writeCommunity = "myCommunityWrite"; // write community name
private Snmp snmp;
private CommunityTarget target;
public SnmpTest() {
try {
TransportMapping transport = new DefaultTcpTransportMapping();
snmp = new Snmp(transport);
Address targetAddress = GenericAddress.parse(address);
target = new CommunityTarget();
target.setCommunity(new OctetString(writeCommunity));
target.setAddress(targetAddress);
target.setRetries(2);
target.setTimeout(1500);
target.setVersion(SnmpConstants.version2c);
PDU command = new PDU();
command.setType(PDU.SET);
command.add(new VariableBinding(new OID("1.3.6.1.2.1.2.2.1.7.1"), new Integer32(2))); // port 1 down
command.add(new VariableBinding(new OID("1.3.6.1.2.1.2.2.1.7.6"), new Integer32(1))); // port 6 up
ResponseEvent response = snmp.send(command, target);
System.out.println("response: " + response);
} catch(Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
SnmpTest test = new SnmpTest();
}
}
I have had good luck with the Westhawk Java SNMP stack.
For a simple SNMP set, the syntax will look something like this:
public static boolean setOid(String hostAddress, int portNumber, String communityName, String oidToSet, String valueToSet) {
SnmpContextPool context = null;
try {
context = new SnmpContextPool(hostAddress, portNumber, SnmpContextFace.STANDARD_SOCKET);
context.setCommunity(communityName);
SetPdu oneSetPdu = new SetPdu(context);
AsnObject obj = new AsnOctets(valueToSet); // use AsnInteger here if you are setting an integer value
oneSetPdu.addOid(oidToSet, obj);
return oneSetPdu.send();
} catch (Exception e) {
//TODO: Handle exceptions properly
e.printStackTrace();
} finally {
if (context != null) {
context.destroy();
}
}
return false;
}
You could try reading the docs...
A (nearly) complete example for the
SNMP4J API usage is the console tool.
It can be found in the
org.snmp4j.tools.console.SnmpRequest
class.
I'm not too sure how to go about getting the external IP address of the machine as a computer outside of a network would see it.
My following IPAddress class only gets the local IP address of the machine.
public class IPAddress {
private InetAddress thisIp;
private String thisIpAddress;
private void setIpAdd() {
try {
InetAddress thisIp = InetAddress.getLocalHost();
thisIpAddress = thisIp.getHostAddress().toString();
} catch (Exception e) {
}
}
protected String getIpAddress() {
setIpAdd();
return thisIpAddress;
}
}
I am not sure if you can grab that IP from code that runs on the local machine.
You can however build code that runs on a website, say in JSP, and then use something that returns the IP of where the request came from:
request.getRemoteAddr()
Or simply use already-existing services that do this, then parse the answer from the service to find out the IP.
Use a webservice like AWS and others
import java.net.*;
import java.io.*;
URL whatismyip = new URL("http://checkip.amazonaws.com");
BufferedReader in = new BufferedReader(new InputStreamReader(
whatismyip.openStream()));
String ip = in.readLine(); //you get the IP as a String
System.out.println(ip);
One of the comments by #stivlo deserves to be an answer:
You can use the Amazon service http://checkip.amazonaws.com
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
public class IpChecker {
public static String getIp() throws Exception {
URL whatismyip = new URL("http://checkip.amazonaws.com");
BufferedReader in = null;
try {
in = new BufferedReader(new InputStreamReader(
whatismyip.openStream()));
String ip = in.readLine();
return ip;
} finally {
if (in != null) {
try {
in.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
}
The truth is: 'you can't' in the sense that you posed the question. NAT happens outside of the protocol. There is no way for your machine's kernel to know how your NAT box is mapping from external to internal IP addresses. Other answers here offer tricks involving methods of talking to outside web sites.
All this are still up and working smoothly! (as of 10 Feb 2022)
http://checkip.amazonaws.com/
https://ipv4.icanhazip.com/
http://myexternalip.com/raw
http://ipecho.net/plain
http://www.trackip.net/ip
http://bot.whatismyipaddress.com (10 Feb 2022)
http://curlmyip.com/ (17 Dec 2016)
Piece of advice: Do not direcly depend only on one of them; try to use one but have a contigency plan considering others! The more you use, the better!
Good luck!
As #Donal Fellows wrote, you have to query the network interface instead of the machine. This code from the javadocs worked for me:
The following example program lists all the network interfaces and their addresses on a machine:
import java.io.*;
import java.net.*;
import java.util.*;
import static java.lang.System.out;
public class ListNets {
public static void main(String args[]) throws SocketException {
Enumeration<NetworkInterface> nets = NetworkInterface.getNetworkInterfaces();
for (NetworkInterface netint : Collections.list(nets))
displayInterfaceInformation(netint);
}
static void displayInterfaceInformation(NetworkInterface netint) throws SocketException {
out.printf("Display name: %s\n", netint.getDisplayName());
out.printf("Name: %s\n", netint.getName());
Enumeration<InetAddress> inetAddresses = netint.getInetAddresses();
for (InetAddress inetAddress : Collections.list(inetAddresses)) {
out.printf("InetAddress: %s\n", inetAddress);
}
out.printf("\n");
}
}
The following is sample output from the example program:
Display name: TCP Loopback interface
Name: lo
InetAddress: /127.0.0.1
Display name: Wireless Network Connection
Name: eth0
InetAddress: /192.0.2.0
From docs.oracle.com
Make a HttpURLConnection to some site like www.whatismyip.com and parse that :-)
How about this? It's simple and worked the best for me :)
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;
public class IP {
public static void main(String args[]) {
new IP();
}
public IP() {
URL ipAdress;
try {
ipAdress = new URL("http://myexternalip.com/raw");
BufferedReader in = new BufferedReader(new InputStreamReader(ipAdress.openStream()));
String ip = in.readLine();
System.out.println(ip);
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
http://jstun.javawi.de/ will do it - provided your gateway device does STUN )most do)
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.*;
import java.util.regex.Pattern;
public class ExternalIPUtil {
private static final Pattern IPV4_PATTERN = Pattern.compile("^(([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\.){3}([01]?\\d\\d?|2[0-4]\\d|25[0-5])$");
private static final String[] IPV4_SERVICES = {
"http://checkip.amazonaws.com/",
"https://ipv4.icanhazip.com/",
"http://bot.whatismyipaddress.com/"
// and so on ...
};
public static String get() throws ExecutionException, InterruptedException {
List<Callable<String>> callables = new ArrayList<>();
for (String ipService : IPV4_SERVICES) {
callables.add(() -> get(ipService));
}
ExecutorService executorService = Executors.newCachedThreadPool();
try {
return executorService.invokeAny(callables);
} finally {
executorService.shutdown();
}
}
private static String get(String url) throws IOException {
try (BufferedReader in = new BufferedReader(new InputStreamReader(new URL(url).openStream()))) {
String ip = in.readLine();
if (IPV4_PATTERN.matcher(ip).matches()) {
return ip;
} else {
throw new IOException("invalid IPv4 address: " + ip);
}
}
}
public static void main(String[] args) throws ExecutionException, InterruptedException {
System.out.println("IP: " + get());
}
}
Get from multiple IP services concurrently such as:
http://checkip.amazonaws.com/
https://ipv4.icanhazip.com/
http://bot.whatismyipaddress.com/
and so on ...
and ExecutorService.invokeAny(tasks) return the result of the first successfully thread. Other tasks that have not completed will be cancelled.
It's not that easy since a machine inside a LAN usually doesn't care about the external IP of its router to the internet.. it simply doesn't need it!
I would suggest you to exploit this by opening a site like http://www.whatismyip.com/ and getting the IP number by parsing the html results.. it shouldn't be that hard!
If you are using JAVA based webapp and if you want to grab the client's (One who makes the request via a browser) external ip try deploying the app in a public domain and use request.getRemoteAddr() to read the external IP address.
System.out.println(pageCrawling.getHtmlFromURL("http://ipecho.net/plain"));
An alternative solution is to execute an external command, obviously, this solution limits the portability of the application.
For example, for an application that runs on Windows, a PowerShell command can be executed through jPowershell, as shown in the following code:
public String getMyPublicIp() {
// PowerShell command
String command = "(Invoke-WebRequest ifconfig.me/ip).Content.Trim()";
String powerShellOut = PowerShell.executeSingleCommand(command).getCommandOutput();
// Connection failed
if (powerShellOut.contains("InvalidOperation")) {
powerShellOut = null;
}
return powerShellOut;
}
I am running a client/server application using JBoss.
How can I connect to the server JVM's MBeanServer? I want to use the MemoryMX MBean to track the memory consumption.
I can connect to the JBoss MBeanServer using JNDI lookup but the java.lang.MemoryMX MBean is not registered with the JBoss MBeanServer.
EDIT: The requirement is for programmatic access to the memory usage from the client.
I wrote a class like this:
import javax.management.remote.JMXServiceURL;
import javax.management.MBeanAttributeInfo;
import javax.management.MBeanInfo;
import javax.management.MBeanServerConnection;
import javax.management.ObjectName;
import javax.management.remote.JMXConnector;
import javax.management.remote.JMXConnectorFactory;
public class JVMRuntimeClient
{
static void main(String[] args) throws Exception
{
if (args == null)
{
System.out.println("Usage: java JVMRuntimeClient HOST PORT");
}
if(args.length < 2)
{
System.out.println("Usage: java JVMRuntimeClient HOST PORT");
}
try
{
JMXServiceURL target = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://"+args[0]+":"+args[1]+"/jmxrmi");
JMXConnector connector = JMXConnectorFactory.connect(target);
MBeanServerConnection remote = connector.getMBeanServerConnection();
/**
* this is the part where you MUST know which MBean to get
* com.digitalscripter.search.statistics:name=requestStatistics,type=RequestStatistics
* YOURS WILL VARY!
*/
ObjectName bean = new ObjectName("com.digitalscripter.search.statistics:name=requestStatistics,type=RequestStatistics");
MBeanInfo info = remote.getMBeanInfo(bean);
MBeanAttributeInfo[] attributes = info.getAttributes();
for (MBeanAttributeInfo attr : attributes)
{
System.out.println(attr.getDescription() + " " + remote.getAttribute(bean,attr.getName()));
}
connector.close();
}
catch(Exception e)
{
System.out.println(e.getMessage());
System.exit(0);
}
}
}
Unlike the JBoss server's MBeanServer, the JVM's MBean server doesn't allow remote monitoring by default. You need to set various system properties to allow that:
http://java.sun.com/javase/6/docs/technotes/guides/management/agent.html
A code example from an IBM article: link
MBeanServerConnection serverConn;
try {
//connect to a remote VM using JMX RMI
JMXServiceURL url = new JMXServiceURL( "service:jmx:rmi:///jndi/rmi://<addr>");
JMXConnector jmxConnector = JMXConnectorFactory.connect(url);
serverConn = jmxConnector.getMBeanServerConnection();
ObjectName objName = new
ObjectName(ManagementFactory.RUNTIME_MXBEAN_NAME);
// Get standard attribute "VmVendor"
String vendor =
(String) serverConn.getAttribute(objName, "VmVendor");
} catch (...) { }
Have you tried launching a JConsole (is $JAVA_HOME/bin) to connect with the server? You should be able to view memory stats from there
The following code lists all mbeans of a given (jmx enabled) java application with their attributes and operations grouped by the domain. Just start the java app you wanna monitor with a fixed jmx port, e.g. by using these vm parameters:
-Dcom.sun.management.jmxremote
-Dcom.sun.management.jmxremote.port=9000
-Dcom.sun.management.jmxremote.local.only=false
-Dcom.sun.management.jmxremote.ssl=false
-Dcom.sun.management.jmxremote.authenticate=false
Then run this main:
import javax.management.*;
import javax.management.remote.JMXConnector;
import javax.management.remote.JMXConnectorFactory;
import javax.management.remote.JMXServiceURL;
import java.io.IOException;
public class JmxListAll {
public static void main(String[] args) throws IOException, MalformedObjectNameException, IntrospectionException, InstanceNotFoundException, ReflectionException {
/*
1. JMXServiceURL.
*/
String jmxHost = "localhost:9000"; // exactly like jconsole localhost:9026
String url = "service:jmx:rmi:///jndi/rmi://" + jmxHost + "/jmxrmi";
JMXServiceURL serviceURL = new JMXServiceURL(url);
/*
2. JMXConnector and the actual serverConnection
*/
JMXConnector connector = JMXConnectorFactory.connect(serviceURL);
MBeanServerConnection serverConnection = connector.getMBeanServerConnection();
/*
3. Walk through the domains and their objects
*/
System.out.println("\n Now we have a look at " + serverConnection.getMBeanCount() + " mbeans!");
int objectCount = 0;
for (String domain : serverConnection.getDomains()) {
System.out.println("\n***********************************************************************************");
System.out.println("DOMAIN: " + domain);
// query all the beans for this domain using a wildcard filter
for (ObjectName objectName : serverConnection.queryNames(new ObjectName(domain + ":*"), null)) {
System.out.println(" objectName " + ++objectCount + ": " + objectName);
MBeanInfo info = serverConnection.getMBeanInfo(objectName);
for (MBeanAttributeInfo attr : info.getAttributes()) {
System.out.print(" attr: " + attr.getDescription());
try {
String val = serverConnection.getAttribute(objectName, attr.getName()).toString();
System.out.println(" -> " + abbreviate(val));
} catch (Exception e) {
System.out.println(" FAILED: " + e);
}
}
for (MBeanOperationInfo op : info.getOperations()) {
System.out.println(" op: " + op.getName());
}
}
}
}
static String abbreviate(String text) {
if (text != null && text.length() > 42) {
return text.substring(0, 42) + "...";
} else {
return text;
}
}
}
As you should see, in the java.lang domain are several memory related mbeans. Pick the one you need.