GithubHelp home page GithubHelp logo

ios-socks-server's Introduction

What

A simple HTTP/SOCKS proxy designed to run on Pythonista on iOS, letting you fake-tether your devices to a phone.

Installation

  • Install Pythonista from the App Store. It's a paid app, but it's worth every penny if you are a power user.
  • Download the code from GitHub.
  • Open the Files app, navigate to Downloads, and tap on the zip file to uncompress it.
  • Move the resulting iOS-SOCKS-Server folder to the Pythonista iCloud directory
  • Open Pythonista, navigate to iCloud, iOS-SOCKS-Server and open the socks5.py script.
  • Optionally, you can tap on the wrench and select Shortcuts... to add the script to your home screen.

Running

  • Connect your devices to the same WiFi network as your phone. If there's no suitable network, you can create a computer-to-computer (ad-hoc) network using your laptop and connect to it with your phone.
  • Open the home screen shortcut (if you made one), or open the socks5.py script in Pythonista and hit Run.
  • Point your devices at the PAC URL (also called script URL, script address, etc.), or configure them to use the SOCKS proxy listed.
    • For iOS devices: open Settings, tap on Wi-Fi, tap on the (i) icon next to the network, scroll down to HTTP Proxy, tap on Configure Proxy, select Automatic, and enter the PAC URL as displayed in Pythonista in the URL field (the URL will look like http://123.123.123.123:8080/wpad.dat).
    • For macOS: open System Preferences -> Network, click on Wi-Fi, hit Advanced..., and under Proxies check SOCKS Proxy and set the host:port to the SOCKS Address as displayed in Pythonista (this will be of the form 123.123.123.123:9876).
      • If you are using an ad-hoc Wi-Fi network (i.e. Wi-Fi menu -> Create Network), you will need to do some extra setup here. Under the TCP/IP tab, copy the existing 169.254.y.z IPv4 address, then switch Configure IPv4 to Manually, enter the 169.254.y.z IP address in both IPv4 Address and Router, and enter 255.255.0.0 as Subnet Mask. Under the DNS tab, add 169.254.y.z to the DNS Servers list.
      • Make sure you set proxy settings in any other application that is not using the system proxy settings.
    • For Windows or Linux, please follow the appropriate instructions for configuring a proxy on your system. It is recommended that you use the PAC URL if possible (also called a setup script or automatic configuration script).
      • On Windows, you may consider using the SSTap project to force all connections to go through the proxy. Disclaimer: this project does not have any affiliation with SSTap and cannot provide support for any issues that arise from its use.
    • For Android: open Settings, Wi-Fi, select your network, expand the Advanced Settings, change the proxy setting to Manual, and enter the host and port for the HTTP proxy. Note that SOCKS proxy support on Android is limited, even when using the PAC URL, so the HTTP proxy is recommended.
      • Many applications on Android do not respect proxy settings, unfortunately, and in those cases you will have to configure the apps manually or use an app like Proxifier to force apps to use the proxy.

Why

Recently, while travelling, I found out that Google Fi doesn't support tethering on iOS (I guess it's a feature they want to keep Android-exclusive or something?). Since my phone has a nice, fast, unblocked connection, I wanted to let my computer access it too.

I previously wrote Socks5-iOS for doing exactly this, but it turned out to be quite cumbersome to deploy and modify. Plus, the app expires frequently (if you don't have an iOS developer account), which makes it annoying if you need it in a pinch. Enter Pythonista - an App Store app which puts a complete Python interpreter on iOS.

This script can be used to implement a functional alternative to tethering, which I refer to fake-tethering. Fake-tethering has some substantial advantages over standard iOS tethering. It works even when carriers ban tethering, and it bypasses limits set on tethering speed since all connections originate from the phone.

While it's easiest to use this with websites, it's actually possible to tunnel any TCP connection over a SOCKS proxy. For example, here's how you would proxy an SSH connection:

ssh -o ProxyCommand='nc -X 5 -x <IP>:9876 %h %p' user@host

Troubleshooting

Doesn't work with an ad-hoc network on macOS

macOS appears to incorrectly assess the Internet as unreachable with an ad-hoc network, even if a proxy is configured. A workaround for this, tested on macOS 10.14, is described under issue #1.

ios-socks-server's People

Contributors

nneonneo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ios-socks-server's Issues

Keeping proxy alive with screen off

Is there any way to keep the proxy alive while the screen is off? Everything works fine for me while the screen is awake, but once I turn if off, the proxy connect dies after a few seconds/minutes.

I know this is probably a limitation of iOS and Apple's App Store requirements for Pythonista, but is there any workaround? I know some apps are able to keep themselves alive by playing a background audio track. Is there some kind of integration point in Pythonista that would allow playing a silent MP3 on loop or something?

For comparison, https://github.com/rickyzhang82/tethering seems to be working fine in the background, though of couse, it's an app that's sideloaded so it probably isn't up to the App Store requirements.

Edit: Or as an alternative, maybe to use Pythonista's ui module to keep the screen on, but display a full screen, solid black image? That way even if the display is technically on, it's all black, so modern iPhones with OLED displays (and in particular, the 13 Pro's ability to scale down to 10Hz) will conserve battery life and screen burn-in health.

What I do wrong?

Hey, I created adhoc, trying to launch script, but received error on import “no module named lib.sock5_server
What I can do wrong? Thx

Version Error

Hello, trying to connect from an android or a iOS phone but getting constant issues:

tried both the pac and socks url to no avail, but keep getting C or G error codes.

Assuming proxy will be accessed over hotspot (bridge100) at 172.20.10.1
Will connect to IPv4 servers over interface pdp_ip0 at 10.131.163.42
PAC URL: http://172.20.10.1:8088/wpad.dat
SOCKS Address: 172.20.10.1:9876

Direction Traffic (Mbps)
In 0.00
Out 0.00

Connections: 4
Total In: 0.03 MB
Total Out: 0.01 MB
Total: 0.04 MB

Errors: 841
Last 5 log messages:
172.20.10.6:42352: Exception: Invalid version 'C' (not configured as SOCKS proxy?)
172.20.10.6:42354: Exception: Invalid version 'C' (not configured as SOCKS proxy?)
172.20.10.6:42360: Exception: Invalid version 'C' (not configured as SOCKS proxy?)
172.20.10.6:42362: Exception: Invalid version 'C' (not configured as SOCKS proxy?)
172.20.10.6:42366: Exception: Invalid version 'C' (not configured as SOCKS proxy?)
Shutting down.

Uploading IMG_4331.jpeg…

Not working for Mac OS 14

Hi there I’ve tried to get this working on my os Mac but having issues, wanted to see if you could help, thanks :)

When running socks5.py it complains about not able to find module "lib".

Following the directions as described results in the main socks5.py not finding any lib.xxx entries. I remove the leading lib. and it gets a little further, but I have to import all the files from the lib folder and then those files can't find stuff.

I don't see an easy fix that doesn't involve touching every file. I also see no easy way to import the entire libraries.

Thoughts?

I am using pythonista 3.

macOS Sonoma Ad-Hoc

Hi,
does anyone know how to run a Wifi from Sonoma?
I can't find a solution how to open a Wifi. The only way seems to enable internet sharing, but that only opens one if I select an internet source network that is connected.

Issues with git/ssh

Hi there!

First off all, all the love for creating the script. Has been a lifesaver.

Unfortunately, I cannot fetch repos from Github, or SSH into a external server.

ssh [email protected]
kex_exchange_identification: read: Operation timed out
banner exchange: Connection to 165.xxx.xx.xxx port 22: Operation timed out
gh repo sync
Post "https://api.github.com/graphql": net/http: TLS handshake timeout
git fetch origin -v
fatal: unable to access 'https://github.com/xxx': error:02FFF03C:system library:func(4095):Operation timed out

Any idea what the issue could be? Nothing specifically interesting is logged in the sock5.py log.

Can’t get it working

Hey man! Thanks for this script. I can’t seem to get it working with ad-hoc on my Mac. Here’s what I do:

  1. Create network on Mac
  2. Join Mac’s new network from iPhone and the Mac itself
  3. Run the socks5 script.
  4. Enter the wdat url in Mac proxy settings.
  5. Open browser

Am I doing something wrong? Thanks for your help! I would love to make this work.

Automatic Proxy config file (pac) issue for iOS devices

Hi nneonneo,

Thank you so much for sharing this useful socks server, I can get it up and run with Pythonista no problem 👍

One issue I noticed is, after the server phone setup and I used other iOS devices (other iPhones) with automatic PAC config, the server end prints out the following exception no matter with wpad.dat or wpad.pac:

192.168.8.2 - - [02/Jan/2024 22:11:27] code 400, message Bad request version ('w´÷\x00*\x9a\x9a\x13\x01\x13\x02\x13\x03À,À+Ì©À0À/̨À')
----------------------------------------
Exception occurred during processing of request from ('192.168.8.2', 59084)
Traceback (most recent call last):
  File "/var/containers/Bundle/Application/313AD80F-5D09-40D2-A230-C53087831B77/Pythonista3.app/Frameworks/Py3Kit.framework/pylib/http/server.py", line 293, in parse_request
    raise ValueError
ValueError

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/var/containers/Bundle/Application/313AD80F-5D09-40D2-A230-C53087831B77/Pythonista3.app/Frameworks/Py3Kit.framework/pylib/socketserver.py", line 317, in _handle_request_noblock
    self.process_request(request, client_address)
  File "/var/containers/Bundle/Application/313AD80F-5D09-40D2-A230-C53087831B77/Pythonista3.app/Frameworks/Py3Kit.framework/pylib/socketserver.py", line 348, in process_request
    self.finish_request(request, client_address)
  File "/var/containers/Bundle/Application/313AD80F-5D09-40D2-A230-C53087831B77/Pythonista3.app/Frameworks/Py3Kit.framework/pylib/socketserver.py", line 361, in finish_request
    self.RequestHandlerClass(request, client_address, self)
  File "/var/containers/Bundle/Application/313AD80F-5D09-40D2-A230-C53087831B77/Pythonista3.app/Frameworks/Py3Kit.framework/pylib/socketserver.py", line 748, in init
    self.handle()
  File "/var/containers/Bundle/Application/313AD80F-5D09-40D2-A230-C53087831B77/Pythonista3.app/Frameworks/Py3Kit.framework/pylib/http/server.py", line 426, in handle
    self.handle_one_request()
  File "/var/containers/Bundle/Application/313AD80F-5D09-40D2-A230-C53087831B77/Pythonista3.app/Frameworks/Py3Kit.framework/pylib/http/server.py", line 404, in handle_one_request
    if not self.parse_request():
  File "/var/containers/Bundle/Application/313AD80F-5D09-40D2-A230-C53087831B77/Pythonista3.app/Frameworks/Py3Kit.framework/pylib/http/server.py", line 306, in parse_request
    self.send_error(
  File "/var/containers/Bundle/Application/313AD80F-5D09-40D2-A230-C53087831B77/Pythonista3.app/Frameworks/Py3Kit.framework/pylib/http/server.py", line 457, in send_error
    self.send_response(code, message)
  File "/var/containers/Bundle/Application/313AD80F-5D09-40D2-A230-C53087831B77/Pythonista3.app/Frameworks/Py3Kit.framework/pylib/http/server.py", line 491, in send_response
    self.log_request(code)
  File "/var/containers/Bundle/Application/313AD80F-5D09-40D2-A230-C53087831B77/Pythonista3.app/Frameworks/Py3Kit.framework/pylib/http/server.py", line 543, in log_request
    self.log_message('"%s" %s %s',
  File "/var/containers/Bundle/Application/313AD80F-5D09-40D2-A230-C53087831B77/Pythonista3.app/Frameworks/Py3Kit.framework/pylib/http/server.py", line 577, in log_message
    sys.stderr.write("%s - - [%s] %s\n" %
  File "/var/containers/Bundle/Application/313AD80F-5D09-40D2-A230-C53087831B77/Pythonista3.app/Frameworks/Py3Kit.framework/pykit_startup.py", line 12, in write
    self.write_stream(s)
ValueError: embedded null character
----------------------------------------

I did try access the PAC url with browser or other Android device, no such issue at all.
To me, the iOS seems sending special request to PAC server and makes it becomes 400.
The server iPhone is running the latest iOS 17.2.1 and Pythonista is on v3.4 (340012) and two client iPhones with one iOS 17.2.1 and one iOS 15.8.

Unable to stream spotify

First off, thanks for the amazing script. Almost everything seems to work. However, Spotify doesn't seem to work, both in Chrome and desktop app (Mac). I found a relevant discussion here.

Also, trying to tunnel OpenVPN connection over the proxy also seems to fail with the error message command 3 unsupported.

Question regarding Wi-Fi

I noticed the iPhone running Pythonista needs to join a Wi-Fi network in order to share the tethered newtork to say a Macbook Pro connected to the same Wi-Fi. But if the iPhone is connected to a Wi-Fi network, why would any traffic being able to use cellular data instead of being forced to use Wi-Fi?

Tethering Still Shows

Hello! I have been using this program for the last three months without issue. Now, when I try to use it, my data usage shows as Hotspot on my plan (and thus is throttled once I've gone over my cap). I'm on iOS 16.5.1 (c) and recently downloaded the most up-to-date code from the repo to see if any recent changes would fix my issue. Is there something in that version of iOS which could be causing issues here? Thanks for a great little script!

Backgrounding

First of all, thanks so much for this solution. It works great. I use Proxifier to route all my computer traffic through the proxy.

But in order to keep the connection active, I need to keep the Pythonista window open on my phone and the screen on. Is there any way around this, or is it just a limitation of that app? Thanks again.

Help

Am i doing this correctly?

  • I connect my laptop to my phones wifi hotspot.
  • Run the socks5.py. it shows the PAC URL and the SOCKS address

From here i have tried manually enter the socks address in the laptop's proxy setting and i have tried using the PAC url. Nothing works. I never get any traffic and connections stays at zero. Any help?

trouble following

Hi,

Thank you so much for putting these files and instructions together. I have a limited Tmobile 10gb cellular hotspot plan that I need to maximize during this time of quarantine because I have no wifi at home. (Comcast Xfinity is the monopoly internet service provider in my area. It has been extremely unreliable and I had to cancel it.)

I'm completely new to Python and data networking, so I couldn't quite understand your instructions and was wondering if you can walk me through it, or better yet create a video walkthrough so it's clear?

INSTALLATION:

  1. I downloaded Pythonista from apple store.
  2. I downloaded the code from the GitHub link.
  3. I was not able to unzip the files in the FILES app, but in Pythonista under "SCRIPT LIBRARY >> This iPhone" I was able to unzip the files and move them over to "SCRIPT LIBRARY >> iCloud". Is this what you mean when you write "move the package to the Pythonista iCloud directory"?
  4. I could not find the "socks5.py" script anywhere inside the unzipped "socks5-ios-master" folder. So I downloaded the "socks5.py.html" file that you posted, but I'm not sure whether to put it in the "SCRIPT LIBRARY >> This iPhone" or "SCRIPT LIBRARY >> iCloud". Regardless of which of the 2 folders I put it in, when I click on this "socks5.py.html" file I see the codes but the RUN triangle button is greyed out.
  5. The wrench icon doesn't allow me to add the script to my homescreen either. I'm not sure what I'm doing wrong. Can you explain/help?

RUNNING:

  1. I am able to connect to the Xfinity mobile public hotspot for free for 1 hour each month, so I can connect both my laptop and phone to this service to follow your instructions, but I'm not sure why this is required and what would happen once the free hour is over. I thought the whole point is to run my cellular hotspot and prevent the carrier from throttling the speed after I reach the 10gb. Can you explain more? Can you also show how to create a computer-to-computer ad-hoc network using my laptop? I have an old mac book pro, and as far as I know if I'm on wifi on the mac then I cannot broadcast a wifi signal from the mac to other devices; I can only broadcast signal over USB for example.

  2. Again, I wasn't able to create a home screen shortcut or open the socks5.py script in Pythonista and hit Run.

  3. I do not understand what "Point your devices at the SOCKS proxy listed (on port 9876), or point them at the PAC (proxy autoconfiguration) URL if they don't support setting a SOCKS proxy (e.g. other iOS devices)" mean at all in laymen terms or how to even do this. Can you explain?

Thank you so much.

Google Meet Does Not Work While Connected to Proxy

Whenever I try to use google meet for video conferences while connected to this proxy the connection does not work. I am able to join, but can't hear or see anyone. The connection then disconnects after 15-30 seconds with an error about a firewall.

This can be replicated by attempting to join any meeting through the https://meet.google.com/ service while connected to the proxy.

Is it possible to fix this proxy to work with google meet?

Suddenly stopped working

I've been using this for the past month with no problems, but suddenly yesterday it just started spitting out errors.

I've been using personal hotspot on my iPhone 13 Pro and connecting to it using a MacBook Pro M1 2021.

I tried using it with an ad-hoc network on the MacBook and it worked for a little while before giving me the same results.

I'd love to help develop a solution but I'm not quite sure where to start.

Error:
Assuming proxy will be accessed over hotspot (bridge100) at 172.20.10.1
Will connect to IPv4 servers over interface pdp_ip0 at 10.157.45.147
PAC URL: http://172.20.10.1:8088/wpad.dat
SOCKS Address: 172.20.10.1:9876
HTTP Proxy Address: 172.20.10.1:9877

Direction Traffic (Mbps)
In 0.00
Out 0.00

Connections: 0
Total In: 0.00 MB
Total Out: 0.00 MB
Total: 0.00 MB

Errors: 19
Last 5 log messages:
172.20.10.5:64556: code 502, message Unable to connect to host ('detectportal.firefox.com', 80): Host ('detectportal.firefox.com', 80) could not be resolved
172.20.10.5:64557: code 502, message Unable to connect to host ('ssl.gstatic.com', 443): Host ('ssl.gstatic.com', 443) could not be resolved
172.20.10.5:64558: code 502, message Unable to connect to host ('detectportal.firefox.com', 80): Host ('detectportal.firefox.com', 80) could not be resolved
172.20.10.5:64559: code 502, message Unable to connect to host ('calendar.google.com', 443): Host ('calendar.google.com', 443) could not be resolved
172.20.10.5:64560: code 502, message Unable to connect to host ('ssl.gstatic.com', 443): Host ('ssl.gstatic.com', 443) could not be resolved
Shutting down.

Bypass local development urls

Just for others that might search this, if you have local development urls that shouldn't be resolved by the SOCKS server, you can simply add this like this on MacOS:

Screenshot 2023-07-25 at 21 03 23

Possible to use WhatsApp and Telegram?

Thank you for this solution, it worked for me like a charm. However, I was first not sure what you meant in the instructions by "point your devices to...". What I did first was to enter the PAC URL that is shown in the python console after running the script in the safari browser of the iPhone that I want to connect to the internet. A pop up opened that asked whether I want to load a pad.dat and I confirmed, and in the python console of the iPhone that has 4G internet I got the prompt

172.20.10.9 - - [21/Aug/2022 10:31:25] "GET /wpad.dat HTTP/1.1" 200 -

however, after that nothing more happened and I could not access any websites.

I then opened the wifi settings of the iPhone without internet and clicked on the "i" info button of the wifi it is connected to, scrolled all down and under "HTTP-Proxy" it was not enabled. I clicked on "configure proxy" and then switched from "off" to "automatic" and then a URL field appeared where I entered the PAC url (similarly to the tutorial here: https://www.ias.edu/wpad-setup-guide-ios). After that accessing the internet through the browser finally worked :)

  1. so my suggestion is that maybe you could add some more detailed instructions in the sevond step of "running"

  2. a question: while the browser and some apps work fine, WhatsApp, Telegram and Instagram do not work. Is there a way to run those apps over the proxy tether as well?

Found a good tool to use along side this (For Windows)

SSTap is a Windows Socks5 proxy enforcer. It makes programs that don't normally run on proxies be forced to do so. It also routes UDP through the proxy. Basically, an all-in-one solution that took me hours to find so I might as well save some trouble for others. It also can be used to forward the proxy to Windows 10/11 built-in hotspot feature by changing the network adapter settings to share it across the hotspot. This allows you to use the proxy on any devices that normally wouldn't support it.

connect error [Errno 60] Operation timed out

I get timed out for all remote.connect in handle_connect.

connect error [Errno 60] Operation timed out

Does Apple still allow Pythonista to use socket?

iPad with data plan is connected to a WiFi router.

iPhone is connected to WiFi router and automatic proxy to wpad.dat.

Is the iPad trying to use the WiFi for Internet? remote.bind binds to CONNECT_HOST 10.x.x.x address.

Use with vpn

Could this potentially work with a VPN being up on the phone, and thus the outbound traffic would go out over the VPN utun device (rather than the first cell0 interface)? Does the outbound proxied (socksified) traffic follow the natural routing table in place on the phone (if the VPN interface is the default gw)?

Thanks 🙂

OSError [Errno 48] Address already in use

As far as I understand this means that python thinks the port is already in use, however, even when switching the port in the code this error will keep popping up. In non jailbroken state when this error happens I just have to restart the phone and it'll usually work after that. But for some reason in jailbroken state on ios 14.5.1, it will always give this error no matter what I do. I'm not sure what the issue could be, it works fine on ios 13.5 with/without jailbreak.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.