How to Access My Localhost from My Android Device

How can I access my localhost from my Android device?

USB doesn't provide network to mobile device.

If both your desktop and phone are connected to the same WiFi (or any other local network), then use your desktop IP address assigned by the router (not localhost and not 127.0.0.1).

To find out the IP address of your desktop:

  • type into the command line ipconfig (Windows) or ifconfig (Unix)

    • on Linux the one-liner ifconfig | grep "inet " | grep -v 127.0.0.1 will yield only the important stuff
    • there's a bunch of suggestions on how to have a similar output on Windows
  • there's going to be a bunch of IP's
  • try all of them (except the forementioned localhost and 127.0.0.1)

If your phone is connected to the mobile network, then things are going to be harder.

Either go hardcore:

  • first find out your router external IP address (https://www.google.de/search?q=myip)
  • then, on the router, forward some port to <your desktop IP>:<server port number>
  • finally use the external IP address and forwarded port

Otherwise use something like xip.io or ngrok.

NOTE: The ifconfig command has been deprecated and thus missing by default on Debian Linux, starting from Debian stretch. The new and recommended alternative for examining a network configuration on Debian Linux is ip command. For example to use ip command to display a network configuration run the following:

ip address

The above ip command can be abbreviated to:

ip a

If you still prefer to use ifconfig as part of your daily sys admin routine, you can easily install it as part of the net-tools package.

apt-get install net-tools

Reference is here

how to access localhost on android device

USB doesn't provide network to mobile device. If it's connected to your wifi, then hit your laptop address provided by the router. If it's connected to your mobile network, then first find out your router external IP address, then forward some port to that 10.0.2.2:portno and finally you'll be able to see that server from your device.

How can I access my localhost from my Android device?

USB doesn't provide network to mobile device.

If both your desktop and phone are connected to the same WiFi (or any other local network), then use your desktop IP address assigned by the router (not localhost and not 127.0.0.1).

To find out the IP address of your desktop:

  • type into the command line ipconfig (Windows) or ifconfig (Unix)

    • on Linux the one-liner ifconfig | grep "inet " | grep -v 127.0.0.1 will yield only the important stuff
    • there's a bunch of suggestions on how to have a similar output on Windows
  • there's going to be a bunch of IP's
  • try all of them (except the forementioned localhost and 127.0.0.1)

If your phone is connected to the mobile network, then things are going to be harder.

Either go hardcore:

  • first find out your router external IP address (https://www.google.de/search?q=myip)
  • then, on the router, forward some port to <your desktop IP>:<server port number>
  • finally use the external IP address and forwarded port

Otherwise use something like xip.io or ngrok.

NOTE: The ifconfig command has been deprecated and thus missing by default on Debian Linux, starting from Debian stretch. The new and recommended alternative for examining a network configuration on Debian Linux is ip command. For example to use ip command to display a network configuration run the following:

ip address

The above ip command can be abbreviated to:

ip a

If you still prefer to use ifconfig as part of your daily sys admin routine, you can easily install it as part of the net-tools package.

apt-get install net-tools

Reference is here

Viewing localhost website from mobile device

To view localhost website from mobile device you have to follow thoses steps :

  • In your computer, you have to retrieve your IP address (Run > cmd > ipconfig)
  • If your localhost use a specific port (like localhost:12345 ), you have to open the port on your computer (Control Panel > System and Security > Firewall > Advanced settings and add Inbound rule)
  • Finally, you can access to your website from mobile device by navigate to : http://192.168.X.X:12345/

Hope it helps

How can I access my localhost from my physical Android device?

Try this:

php artisan serve --host 0.0.0.0 --port 80

Just make sure that the port is free.

Reference: https://stackoverflow.com/a/30675683/5192105

Access localhost from Android device

Check public ip of your pc by ifconfig command in terminal
then use YOUR_IP/myphpServer

If you are in local network (router or LAN) then use your local_ip/myphpServer (make sure your mobile is also in same network)

If your mobile doesn't have internet connection then go for Android USB Tethering



Related Topics



Leave a reply



Submit