สถานการณ์คือ VPN ของที่ทำงานต่ออยู่บน iPad ของผม แต่เครื่องที่ต้องเข้าเว็บภายในและ server ที่ทำงานคือ MacBook ทางออกที่ผมให้ Claude Code ทำคือให้ iPad เป็นตัวกลาง แล้วให้ Mac วิ่งผ่านมัน
แอปที่ได้ชื่อ PadProxy มันเปิด proxy เล็กๆ บน iPad ให้ Mac ในเครือข่ายเดียวกันส่งทราฟฟิกผ่านมา ทราฟฟิกก็จะออกไปทาง VPN ที่ iPad ต่ออยู่


เงื่อนไขที่ผมตั้งไว้ตั้งแต่บรรทัดแรก
prompt ยาวๆ ภาษาอังกฤษที่ผมให้ Claude Code ครั้งเดียว (ผมวางมา ไม่ได้พิมพ์สดทั้งหมด) ข้อที่สำคัญที่สุดคือห้ามใช้ NetworkExtension หรือ API ของ VPN เพราะถ้าแอปไปยุ่งกับระบบ VPN มันอาจตัดการเชื่อมต่อที่ที่ทำงานของผมทิ้ง ผมให้มันเขียนเป็นแค่ socket server ธรรมดาที่รับการเชื่อมต่อจากเครื่องอื่นในวงเดียวกัน ใช้ Network.framework ของ Apple ไม่พึ่งไลบรารีข้างนอก และรองรับ CONNECT เพื่อให้ HTTPS ผ่านได้
จุดที่ผมว่าน่าสนใจคือ prompt บอกเหตุผลของข้อห้ามด้วย ไม่ใช่แค่ห้ามเฉยๆ คือ "ห้ามเพราะต้องอยู่ร่วมกับ VPN ที่กำลังต่ออยู่" การบอกเหตุผลแบบนี้ช่วยให้ AI เลือกทางอื่นในแอปได้สอดคล้องกัน
บ่ายวันเดียวกัน ติดตั้งลง iPad
ผมสั่งสั้นๆ ว่า "deploy to my ipad" ลองต่อ Mac เข้าไป เว็บเบราว์เซอร์ใช้ได้ แต่คำสั่ง ssh ในเทอร์มินัลยังเข้า server ที่ทำงานไม่ได้ ปรากฏว่าเทอร์มินัลไม่สนการตั้งค่า proxy ของระบบ macOS มันพยายามต่อตรงผ่านเน็ตบ้าน ต้องบอก ssh เองให้ใช้ proxy ผ่าน ProxyCommand:
ssh -o "ProxyCommand nc -X connect -x [ip-ของ-ipad]:8080 %h %p" [user]@[server]
พอใส่แบบนี้ก็ต่อได้ ผมสั่งต่อว่า "ok it work now deploy it to my iphone17 pro also" เพื่อให้ใช้บน iPhone ได้ด้วย
เอาไปใช้กับงานจริง และแอปช่วยแก้ปัญหาตัวเอง
อีกสองวันต่อมา ผมเปิดหน้าเว็บภายในบน server ที่ทำงานไม่ได้ เลยลองให้ Claude ssh เข้าไปดูเองผ่านแอปนี้ เจอว่าไฟร์วอลล์ของ server ไม่ให้ช่วง IP ของ VPN เข้าบางพอร์ต มันเพิ่มกฎอนุญาตให้ครบห้าพอร์ต แล้วหน้าเว็บก็เปิดได้ ผมชอบตรงที่เครื่องมือที่ AI สร้าง ถูกใช้แก้งานจริงโดย AI ตัวเดียวกัน (ผมไม่ได้ใส่รหัสผ่านของ server ไว้ในบทความ และถ้าทำใหม่ ควรใช้ ssh key แทนการให้รหัสผ่านในคำสั่ง)
จากของใช้เอง ไปเป็นแอปที่ส่งขึ้นสโตร์ได้
วันที่ 21 ตุลาคม ผมให้เก็บให้พร้อมส่งสโตร์: ไอคอน ปุ่ม tip jar (ผู้ใช้อยากให้กาแฟได้ในราคา $0.99, $4.99 หรือ $9.99 โดยไม่ปลดล็อกอะไรเพิ่ม) รองรับ iPhone ด้วย และเก็บการเล่นเสียงเงียบๆ ที่เอาไว้กัน iOS หยุดแอปตอนอยู่หลังฉาก ไว้เฉพาะบิลด์ตอน debug ส่วนบิลด์สำหรับสโตร์ไม่มีส่วนนี้
สองวันต่อมาผมเพิ่มแอปคู่หูบน Mac ชื่อ PadProxyMac เป็นไอคอนบนแถบเมนู iPad จะประกาศตัวเองผ่าน Bonjour ให้ Mac หาเจอเอง และกดเปิดปิด proxy ของระบบ macOS ได้ในคลิกเดียว จะได้ไม่ต้องไปตั้งค่าในหน้า System Settings ทุกครั้ง
prompt ที่ผมใช้จริง
อันแรกคือ prompt ภาษาอังกฤษยาวที่ผมวางทั้งก้อน (ผมไม่ตัด เพราะแต่ละข้อมีเหตุผลของมัน) ใช้ได้เลยถ้าคุณมีสถานการณ์คล้ายกัน ข้อสุดท้ายในนั้นพูดถึงการตั้งค่า Info.plist ซึ่งจำเป็น ไม่งั้นแอปจะรับการเชื่อมต่อจาก Mac ไม่ได้
1. prompt ตั้งต้น (20 ต.ค.)
You are an expert iOS/iPadOS developer. Build a complete, production-ready native iPadOS app in Swift and SwiftUI that acts as a local HTTP and HTTPS (CONNECT) proxy server.
### Critical Architecture Constraints
1. DO NOT use NetworkExtension, NEPacketTunnelProvider, or any VPN APIs. The app must run strictly as a user-space socket server so that it can run concurrently alongside an active GlobalProtect VPN tunnel without terminating it.
2. Use Apple's native `Network.framework` (`NWListener` and `NWConnection`) without third-party dependencies.
3. Support HTTP proxy requests and the HTTP `CONNECT` method (essential for tunneling HTTPS / SSL traffic between the client and destination).
### Requirements
#### 1. Core Proxy Engine (Network.framework)
- Implement a `ProxyServer` class using `NWListener` listening on `0.0.0.0` (default port `8080`, configurable).
- When an incoming connection arrives from the LAN (MacBook):
- Read the HTTP request header.
- If the method is `CONNECT host:port HTTP/1.1`:
- Establish an outbound `NWConnection` to the target `host:port`.
- Once connected, send `HTTP/1.1 200 Connection Established\r\n\r\n` back to the client.
- Enter bidirectional raw TCP streaming (forward bytes from client to target, and target to client) until either side closes.
- If the method is standard HTTP (`GET`, `POST`, etc.):
- Parse the absolute URI from the request line, establish the outbound connection, forward the original request, and stream the response back.
- Implement robust error handling, socket teardown, and cancellation when connections drop.
#### 2. Local IP Address Detection
- Provide a utility to query the active network interface (`en0` / Wi-Fi or `pdp_ip0` / Hotspot) using `getifaddrs` in Swift to display the iPad's current local IPv4 address (e.g., `192.168.1.X` or `172.20.10.1`).
#### 3. SwiftUI Interface
- Clean, iPad-friendly dashboard showing:
- Server Status (Running / Stopped indicator with an animated badge).
- iPad Local IP address (with a "Copy" button).
- Port input field (default `8080`).
- Big Start / Stop toggle button.
- Active Connections Counter and live connection log view (method, host, status).
- Clear instructions block showing the user what to type into their MacBook Proxy Settings.
#### 4. Background & Permissions Configuration
- Specify all required entries for `Info.plist`:
- `NSLocalNetworkUsageDescription` (required by iOS 14+ to accept incoming connections over Wi-Fi).
- Background Execution capabilities (e.g., Audio keepalive or idle-timer disabling via `UIApplication.shared.isIdleTimerDisabled = true`) to prevent iOS from suspending the socket server while running in the background.
Please provide the complete, compilable Swift code organized cleanly into classes, and explain how to set it up in Xcode.2. ลงเครื่อง
deploy to my ipad
3. ใช้งานได้แล้ว ลงอีกเครื่อง
ok it work now deploy it to my iphone17 pro also
4. ให้ AI แก้ปัญหาบน server ผ่าน proxy นี้ (22 ต.ค.)
why i cannot open web http://[server-ip]:9000/[path] how to fix it you can ssh to check config on this server by ssh -o "ProxyCommand nc -X connect -x [ip-ของ-ipad]:8080 %h %p" [user]@[server-ip]