### Domain Filtering Example (Blacklist/Whitelist) Source: https://github.com/enthus1ast/nimsocks/blob/master/README.md This example shows how to configure domain filtering using blacklist and whitelist files. The server supports exact domain matches, prefix matching, and suffix matching. ```nim #... (assuming proxy is already initialized) ## Add a valid user / password combination proxy.addUser("hans", "peter") ## For a static host replacement: proxy.staticHosts.add("peter.peter", "example.org") asyncCheck proxy.serve() asyncCheck proxy.dumpThroughput() runForever() ``` -------------------------------- ### Domain Filtering Example (Fancy Filter) Source: https://github.com/enthus1ast/nimsocks/blob/master/README.md Demonstrates advanced domain filtering using keywords like 'con' (contains), 'end' (ends with), 'eql' (exact match), and 'sta' (starts with). Whitelist entries take precedence over blacklist entries. ```nim #'#' is a comment # all domains containing nim con nim # ending with end nim-lang.org end wikipedia.org # exact match eql github.org # startswith sta foo.baa ``` -------------------------------- ### Client: Proxy Hopping Example Source: https://github.com/enthus1ast/nimsocks/blob/master/README.md Demonstrates how to chain SOCKS proxies by having one SOCKS server connect to another. This allows for multi-hop proxying to reach a final target. ```nim var sock = waitFor asyncnet.dial("firstSocks.loc", Port 1080 ) assert true == waitFor sock.doSocksHandshake(methods={NO_AUTHENTICATION_REQUIRED}) assert true == waitFor sock.doSocksConnect("secondSocks.loc", Port 1080) assert true == waitFor sock.doSocksHandshake(methods={NO_AUTHENTICATION_REQUIRED}) assert true == waitFor sock.doSocksConnect("mytarget.loc", Port 80) sock.send("FOO") # from here we speak to "mytarget.loc" sock.close() # will destroy the whole tunnel ``` -------------------------------- ### Configure and Run SOCKS Server Source: https://github.com/enthus1ast/nimsocks/blob/master/README.md Instantiate a SOCKS server, configure allowed versions and authentication methods, add users, and set up static hosts. The server then starts serving requests and can dump throughput statistics. ```nim import nimSocks/server var proxy = newSocksServer() echo "SOCKS Proxy listens on: ", proxy.listenPort proxy.allowedSocksVersions = {SOCKS_V4, SOCKS_V5} proxy.allowedAuthMethods = {USERNAME_PASSWORD, NO_AUTHENTICATION_REQUIRED} ## Add a valid user / password combination proxy.addUser("hans", "peter") ## For a static host replacement: proxy.staticHosts.add("peter.peter", "example.org") asyncCheck proxy.serve() asyncCheck proxy.dumpThroughput() runForever() ``` -------------------------------- ### Command Line Usage with curl Source: https://github.com/enthus1ast/nimsocks/blob/master/README.md Example of using curl with SOCKS5 proxy options for accessing a web resource. Shows how to specify the proxy address and authentication. ```bash $ curl --socks5-basic --socks5 hans:peter@127.0.0.1:1080 google.de ``` -------------------------------- ### Command Line Usage with ncat Source: https://github.com/enthus1ast/nimsocks/blob/master/README.md Example of using ncat with SOCKS proxy options for connecting to a remote host. Includes specifying proxy address, type, and authentication credentials. ```bash $ ncat --proxy 127.0.0.1:1080 --proxy-type socks5 --proxy-auth hans:peter 2a02:bbb:aaa:9daa:ff11:a4ff:aaaa:bbbb 9090 ``` -------------------------------- ### Client: Establish SOCKS Connection Source: https://github.com/enthus1ast/nimsocks/blob/master/README.md Use the nimSocks client library to upgrade an existing socket to a SOCKS connection. This involves performing a handshake with the SOCKS server and then initiating a connection to a target host. ```nim var sock = waitFor asyncnet.dial("127.0.0.1", Port 1080 ) # dial to the socks server assert true == waitFor sock.doSocksHandshake( username="username", password="password", methods={NO_AUTHENTICATION_REQUIRED, USERNAME_PASSWORD} # the "best" auth supported gets choosen by the server! ) assert true == waitFor sock.doSocksConnect("example.org", Port 80) # instruct the proxy to connect to target host (by tcp) # Then do normal socket operations sock.send("FOO") ``` -------------------------------- ### Configure Static Hosts Source: https://github.com/enthus1ast/nimsocks/blob/master/README.md Add static host entries to the proxy configuration. This allows specific domain names to always resolve to a given IP address or DNS name, overriding normal DNS resolution. ```nim #... proxy.staticHosts.add("foo.loc", "example.org") proxy.staticHosts.add("baa.loc", "192.168.1.1") #... ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.