Any known method to browse PC localhost from iPhone via USB cable (sans wifi)? - iphone

When I run a test mobile site in Visual Studio 2010 and it gives me a localhost:4331 I would like to find a way to forward the HTTP port over to my iPhone through the USB cable so I can test on the device.
They key here is using the USB cable instead of a wireless network, as I am working in a very locked down environment where no wifi is available.
I want the iPhone to connect to the internet through the USB cable, so it would be using my Windows LAN connection and have the Windows localhost be visible to iPhone Safari.

I don't think you can do this. You either need to use WiFi, or have your server exposed on a public network that is accessible via your carrier. You might have some more options with a Jailbroken device.

Follow these steps to see it working -
Connect your iPhone to your PC via USB
Find Tethering and Hotspot setting and enable "USB tethering" on your iPhone.
When your PC has been successfully been connected to the internet, type
"ipconfig" in the command prompt. Just copy the ipv4 address(along with port) and enter it on
the browser with your localhost active
If everything goes fine, then enter the same ipv4 address on your mobile(along with port) web
browser.
The server homepage will open on the iPhone.
I hope this helps.

Related

Accessing localhost API from android device

I'm developing a Flutter app on a physical android device, I don't know much about networking and I'm having a trouble using an API from the phone to a local database on my laptop.
I reviewed all the answers in this post
Cannot connect to localhost API from Android app
Nothing seems to work for me, I'm using Apache server on XAMPP, and the API works just fine from the laptop (127.0.0.1:8000/api/Students) but when I try to access it from the phone it doesn't work (I replaced 127.0.0.1 with the IP of my laptop which I took from ipconfig)
XAMPP control panel
when I try to access the server from the phone using laptop-IP:80 it access normally the same with laptop-IP:80/phpmyadmin
XAMPP dashboard
but only when my phone is connected to the laptop mobile hotspot, when I connect the two devices to the same WIFI network it shows that it's unreachable:
but when I try laptop-IP:8000/api/Students this happens:
this site can't be reached
I tried to modify Apache httpd.conf:
#Listen 12.34.56.78:80
Listen 8000 <-- Added this
from what I understood this makes the server listens to port 8000 but I'm left with the same problem
NOTE: all the pictures show my attempts to use the API on my phone's Chrome browser
You need to do some tweaks to the url to access it in the device as localhost is only known to the machine not the devices on which the app is running.
The urls are different for different devices
Emulator
Real phone (with usb debugging)
1.Emulator
static const baseUrl = "http://10.0.2.2:8000";
2.Real Device
static const baseUrl = "http://localhost:8000";
Additionally you need to run these command in your cmd,
adb reverse tcp:8000 tcp:8000
Now your requests would go like:
get('$baseUrl/api/Students');

Using iPhone to connect to localhost running on Windows 10 Computer (No USB)

I'm developing an API and I am hosting it on my desktop server running Windows 10 using php -S localhost:8080 -t D:\Code\Projects\Website.
I want to be able to use my iPhone to visit this localhost:port webpage without plugging my iPhone into my computer via a USB since they are on the same network. Although, my desktop does not have WiFi capabilities; rather it is using an ethernet cable plugged directly into my router. When I use this address on my desktop, it works fine and takes me to my index.php page.
If I open my default gateway 10.0.0.1 NETGEAR Genie, I can see my iPhone's IP is listed as an "attached device."
I added an Inbound rule to my Firewall (TCP, port:8080, allow access, domain/public/private enabled), but I still cannot use my iPhone to reach this webpage using [my_desktop_ipv4]:[8080].
Would there be any security restrictions from my iPhone's iOS settings? Or am I missing something?

ionic serve with wifi hotspot to test on mobile

I'm trying to test our app in the mobile browser.
I started a wifi hotspot
Ran ionic serve on our project root
Connected to wifi on mobile device
On mobile browser went to http://localhost:8100
but I get a page not found. Shouldn't the ionic app load on browse if I connect to the wifi hotspot of the pc running the app server?
ionic serve like in the accepted answer did not work for me. But
ionic serve --host=COMMON_NETWORK_IP and connecting to
COMMON_NETWORK_IP:8100 on the phone, did.
Look up your COMMON_NETWORK_IP via ifconfig (unix) or ipconfig (windows).
If you are on WiFi and use a mac, you can also use a GUI:
localhost is your local address. If you want to access to the ionic app served by your PC from your mobile device browser, you should use the ip address of your PC instead of localhost, since localhost is the address of your mobile device.
So just run an ifconfig (unix) or ipconfig (windows) on your terminal and access to the app with this address from your mobile device : http://IP_OF_YOUR_PC:8100
This may not work depending on your firewall rules.
The best way to do it:
Make Personal Hotspot from your mobile Device to your Computer
run ionic serve
Read the the output this command throws. There you can see an External IP-Adress
Open the Browser on your smartphone and use the Exernal IP-Adress + 8100 (Port)
For example: http://192.168.32.12:8100
All you need to do is make sure your laptop and mobile are on the same Wifi Connection
Just Run ionic serve
Network: http://192.168.1.***:8100/
Type that network address in your mobile browser
It works for all create-react-app & vue-cli
Hot reload will also work
If you don't have WiFi use a mobile hotspot

Connecting Real device to Android emulator

I am developing a network app for Android and I'm still stuck on connecting my real Android device with an device-emulator running on my desktop computer.
I've created private network with a router, so the only ones connected to the network are my pc and my mobile phone, in order to avoid firewall/closed ports problems.
My PC ip is 192.168.1.100 and I'm trying to ping each other so I can sea reachability of each network node. Ping works fine from my PC (not the emulator console) to the phone.
The problem is that I want to ping the PC-emulator from my mobile phone, not the PC itself... For that, I use the emulator console... Should I use my computer IP or should I use another one? I've seen some ip's like "10.0.x.x" here http://developer.android.com/guide/developing/tools/emulator.html
But I guess those are for connecting two EMULATORS, right?
Besides, I've tried to connect them by socket, creating a redirection for the port via Emulator console, but still can't connect them.
Any clues?
Thanks!!
I tried the early solution I gave you and it didn't work. As you said maybe the reason is the redir command of the emulator console only redirects packets comming from the localhost.
So I searched for a simple proxy server and used it in the same machine to test it out.
http://www.java2s.com/Code/Java/Network-Protocol/Asimpleproxyserver.htm
With this I used the following configuration:
on the proxy:
String host = "localhost";
int remoteport = 3000;
int localport = 4000;
Then run the emulator instance:
Server socket listening on port 2000.
Open telnet instance and issue "redir add tcp:3000:2000"
And finally on the real device open a socket to the machine address on port 4000.
So the network map looks like:
Device <-> machine:4000 Proxy machine:3000 <-> :3000 Emulator :2000 -> Application
This worked for me using the same application on the device and emulator.
I've reached the conclusion that emulator can only receives packets coming from the loopback (127.0.0.1), since when you issue "redir add tcp:port:newPort, it only redirects the first port (associated to the loopback) to the second port (associated to the "emulator virtual ip").
I've tried to create a bridge, which redirects all the packets coming to my pc to the IP 127.0.0.1, but still not works. Thus, I think the emulator has been developed only to communicate with other emulators...
I hope anyone that comes here contradicts me.
You may be able to connect a real device with an emulator instance.
Did you tried setting a redirection on the emulated device and then connect the real device trough a java socket?
For example:
On the emulated device open a server socket listening on port 2000, then open a telnet connection and issue the command:
redir add tcp:4000:2000
Finally, open a socket on the real device to your machine address (192.168.1.100) on port 4000.

Capturing network traffic while the application is running on iPhone and connected to xcode

Is there any way I can capture network traffic (using application like Ethereal, on Mac ) while the application is running on iPhone and connected to xcode
Thanks
Connect you mac using an ethernet cable. Share your network connection on the mac over your AirPort. Attach the iPhone to your Mac's ad-hoc network.
Run Wireshark or HTTPScoop on your mac and you will be able to see all traffic from the iPhone.
I'm no aware of any way to do this for the WAN connection though. I'd be surprised if it is possible.
To capture packets from your iPhone using Wireshark, you have to first get your device id for the phone from iTunes. Plug in your iPhone via USB to your Mac...then open iTunes and click the iPhone icon in top navbar.
You can't copy the UUID, so you have to write it down manually. After you have the UUID, you'll need to mount the device.
Open a terminal and type: rvictl -s <device-id>
I created an alias in ~/.bash_aliases as alias mntios='rvictl -s <device-id>' -- as long as you have the same phone your device UUID won't change, even if you re-install the OS.
Once you have the device mounted startup wireshark. brew install wireshark (see: http://brew.sh)
One of the network adaptors should be rvi0 -- this is the network interface for your iPhone.
Now you can capture packets -- double click it to start capturing.
If you want to filter for specific urls you can type a filter like: http.request.full_uri contains <string-in-url> to filter requests.
On your computer, run an HTTP debugging proxy like Charles (Mac) or Fiddler2 (Windows). In the phone's wi-fi settings, turn on the HTTP proxy, entering your computer's IP address and the port number of the proxy. Make the sure the proxy is configured to allow connections from your phone. (It may allow localhost-only by default.)