github.com/igoogolx/clash@v1.19.8/docs/premium/script-shortcuts.md (about) 1 --- 2 sidebarTitle: "Feature: Script Shortcuts" 3 sidebarOrder: 6 4 --- 5 6 # Script Shortcuts 7 8 Clash Premium implements the Scripting feature powered by Python3, enableing users to programmatically select policies for the packets with dynamic flexibility. 9 10 You can either controll the entire rule-matching engine with a single Python script, or define a number of shortcuts and use them in companion with the regular rules. This page refers to the latter feature. For the former, see [Script](./script.md). 11 12 This feature enables the use of script in `rules` mode. By default, DNS resolution takes place for SCRIPT rules. `no-resolve` can be appended to the rule to prevent the resolution. (i.e.: `SCRIPT,quic,DIRECT,no-resolve`) 13 14 ```yaml 15 mode: Rule 16 17 script: 18 engine: expr # or starlark (10x to 20x slower) 19 shortcuts: 20 quic: network == 'udp' and dst_port == 443 21 curl: resolve_process_name() == 'curl' 22 # curl: resolve_process_path() == '/usr/bin/curl' 23 24 rules: 25 - SCRIPT,quic,REJECT 26 ``` 27 28 ## Evaluation Engines 29 30 [Expr](https://expr.medv.io/) is used as the default engine for Script Shortcuts, offering 10x to 20x performance boost compared to Starlark. 31 32 [Starlark](https://github.com/google/starlark-go) is a Python-like langauge for configuration purposes, you can also use it for Script Shortcuts. 33 34 ## Variables 35 36 - network: string 37 - type: string 38 - src_ip: string 39 - dst_ip: string 40 - src_port: uint16 41 - dst_port: uint16 42 - inbound_port: uint16 43 - host: string 44 - process_path: string 45 46 ::: warning 47 Starlark is missing `process_path` variable for now. 48 ::: 49 50 ## Functions 51 52 ```ts 53 type resolve_ip = (host: string) => string // ip string 54 type in_cidr = (ip: string, cidr: string) => boolean // ip in cidr 55 type in_ipset = (name: string, ip: string) => boolean // ip in ipset 56 type geoip = (ip: string) => string // country code 57 type match_provider = (name: string) => boolean // in rule provider 58 type resolve_process_name = () => string // find process name (curl .e.g) 59 type resolve_process_path = () => string // find process path (/usr/bin/curl .e.g) 60 ```