STUNClient
Stun client written in Swift for exploration of NAT traversal details (iOS/macOs/Linux)
Install / Use
/learn @madmag77/STUNClientREADME
StunClient
Simple Stun client that connects to Stun server using UDP and asks for your external IP and Port. Can be used both from iOS and macOS.
Requirements
- iOS 10.0+ / macOS 10.12+
- Xcode 11+
- Swift 5.2+
Installation
Swift Package Manager
The Swift Package Manager is a tool for automating the distribution of Swift code and is integrated into the swift compiler.
Just add Stun Client to the dependencies of your Package.swift
dependencies: [
.package(url: "https://github.com/madmag77/STUNClient.git", .upToNextMajor(from: "1.0.3"))
]
or using Xcode Menu: File->Swift Packages->Add Package Dependency where just insert https://github.com/madmag77/STUNClient.git in the search line.
CocoaPods
CocoaPods is a dependency manager for Cocoa projects. Add StunClient in the Podfile:
pod 'StunClient'
iOS Example project with StunClient as a CocoaPod you can find here: https://github.com/madmag77/STUNClient/tree/master/iOSExampleWithPods
Manually
In terminal:
git clone https://github.com/madmag77/STUNClient
cd STUNClient
swift run
You should see the following output:
LOG: Start Who Am I procedure with Stun server 64.233.163.127:19302 from local port 14135
LOG: XOR_MAPPED_ADDRESS
Family: 1
Port: 54668
Address: xxx.xxx.xxx.xxx
COMPLETED, my address: xxx.xxx.xxx.xxx my port: 54668
Then you can try iOS example:
cd iOSExample
open STUNClient.xcodeproj
Choose simulator and run the project.
Usage
This is how Stun Client can be used (Google Stun IP address and port are being used here):
client = StunClient(stunIpAddress: "64.233.163.127", stunPort: 19302, localPort: UInt16(14135))
let successCallback: (String, Int) -> () = { [weak self] (myAddress: String, myPort: Int) in
guard let self = self else { return }
print("COMPLETED, my address: \(myAddress) my port: \(myPort)")
}
let errorCallback: (StunError) -> () = { [weak self] error in
guard let self = self else { return }
print("ERROR: \(error.localizedDescription)")
}
let verboseCallback: (String) -> () = { [weak self] logText in
guard let _ = self else { return }
print("LOG: \(logText)")
}
client
.whoAmI()
.ifWhoAmISuccessful(successCallback)
.ifError(errorCallback)
.verbose(verboseCallback)
.start()
Related Skills
node-connect
343.1kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
90.0kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
343.1kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
343.1kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
