Q:

How to determine if tests are running local or on the remote server

According to this tutorial, I am able to upload files on the website while running my tests locally and on the remote server. 

As in the tutorial is:

For those of you doing this locally, all you need to do is use the
  sendKeys command to type the local path of the file in any file field.
  This works like a charm in all drivers. When moving this test to a
  remote server (such as, for example, our Selenium 2 Cloud), all you
  need to do is use the setFileDetector method to let WebDriver know
  that you’re uploading files from your local computer to a remote
  server instead of just typing a path.

on the remote server I have to use:
driver.setFileDetector(new LocalFileDetector());
...
upload.sendKeys("/Path/to/image.jpg");

and local just:
upload.sendKeys("/Path/to/image.jpg");

And this all works fine. Only the problem is, that there is no information how to determine if my tests are running local or on the remote server.

I have tried to determine instance of the webDriver:
WebDriver proxiedWebDriver = ((WebDriverFacade) getDriver()).getProxiedDriver();
if (proxiedWebDriver instanceof RemoteWebDriver) {
    ((RemoteWebDriver)proxiedWebDriver).setFileDetector(new LocalFileDetector());
}

but it seems like both(local and remote) cases are using RemoteWebDriver while running, because in every case I'm passing if condition.
How can I determine if my tests are running local or remote?

A:

To get the address of the remote server you can use HttpCommandExecutor like this:
HttpCommandExecutor ce = (HttpCommandExecutor) ((RemoteWebDriver)driver).getCommandExecutor();
String remoteAddress = ce.getAddressOfRemoteServer().toString();
String localAddress = null;

try (Socket socket = new Socket()) {
    socket.connect(new InetSocketAddress("google.com", 80));
    localAddress = socket.getLocalAddress().getHostAddress();
} catch (IOException e) {
    e.printStackTrace();
}

if (remoteAddress.contains("localhost") || remoteAddress.contains(localAddress)) System.out.println("Local machine");
else System.out.println("Remote machine");

The above code gets the Remote Server address (HUB) and compares it with your public IP address. It should give you the information if you are running local or remote server

