xray_sdk 0.0.22-beta
xray_sdk: ^0.0.22-beta copied to clipboard
Dart library for generating Xray Core configurations and working with links (parsing/generation) for V2Ray protocols.
example/xray_sdk_example.dart
import 'dart:convert';
import 'package:xray_sdk/config.dart';
import 'package:xray_sdk/packages/core/index.dart';
import 'package:xray_sdk/share.dart';
final exJson = """
{
"log": {
"access": "",
"error": "",
"loglevel": "warning"
},
"inbounds": [
{
"tag": "socks",
"port": 10808,
"listen": "0.0.0.0",
"protocol": "socks",
"sniffing": {
"enabled": true,
"destOverride": [
"http",
"tls"
],
"routeOnly": false
},
"settings": {
"auth": "noauth",
"udp": true,
"allowTransparent": false
}
},
{
"tag": "http",
"port": 10809,
"listen": "0.0.0.0",
"protocol": "http",
"sniffing": {
"enabled": true,
"destOverride": [
"http",
"tls"
],
"routeOnly": false
},
"settings": {
"auth": "noauth",
"udp": true,
"allowTransparent": false
}
}
],
"outbounds": [
{
"tag": "mb-balancer-2-host-75406",
"protocol": "vless",
"settings": {
"vnext": [
{
"address": "dev.ipcheck.site",
"port": 443,
"users": [
{
"id": "4f80cdff-8000-43b5-997a-05bd4a6a42a5",
"security": "auto",
"encryption": "none",
"email": "https://gozargah.github.io/marzban/",
"alterId": 0,
"flow": "xtls-rprx-vision"
}
]
}
]
},
"streamSettings": {
"network": "tcp",
"security": "tls",
"tlsSettings": {
"serverName": "dev.ipcheck.site",
"allowInsecure": false,
"fingerprint": "edge",
"alpn": [
"http/1.1",
"h2",
"h3"
],
"show": false
},
"tcpSettings": {
"header": {
"type": "none",
"request": {
"headers": {
"Host": [
"dev.ipcheck.site"
],
"User-Agent": [
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.3.1 Safari/605.1.15"
]
}
}
}
}
}
},
{
"tag": "mb-balancer-2-host-75407",
"protocol": "vless",
"settings": {
"vnext": [
{
"address": "dev.ipcheck.site",
"port": 44321,
"users": [
{
"id": "4f80cdff-8000-43b5-997a-05bd4a6a42a5",
"security": "auto",
"encryption": "none",
"email": "https://gozargah.github.io/marzban/",
"alterId": 0,
"flow": "xtls-rprx-vision"
}
]
}
]
},
"streamSettings": {
"network": "tcp",
"security": "reality",
"realitySettings": {
"serverName": "dev.ipcheck.site",
"fingerprint": "firefox",
"show": false,
"publicKey": "hHm2hgQv81N-ROYi9Db-zqsDtuy-Xt8-YOWD0IDBIAc",
"shortId": "f68eb4203d"
}
}
},
{
"tag": "mb-balancer-2-host-75367",
"protocol": "vless",
"settings": {
"vnext": [
{
"address": "pass.seqgen.pro",
"port": 12443,
"users": [
{
"id": "4f80cdff-8000-43b5-997a-05bd4a6a42a5",
"security": "auto",
"encryption": "none",
"email": "https://gozargah.github.io/marzban/",
"alterId": 0,
"flow": "xtls-rprx-vision"
}
]
}
]
},
"streamSettings": {
"network": "tcp",
"security": "reality",
"realitySettings": {
"serverName": "pass.seqgen.pro",
"fingerprint": "firefox",
"show": false,
"publicKey": "FwXsSwduJy7rIdQ171oWtSL54rqL0H45kR-Hbogizh8",
"shortId": "79794618"
}
}
},
{
"tag": "mb-balancer-2-host-75405",
"protocol": "vless",
"settings": {
"vnext": [
{
"address": "pass.seqgen.pro",
"port": 44322,
"users": [
{
"id": "4f80cdff-8000-43b5-997a-05bd4a6a42a5",
"security": "auto",
"encryption": "none",
"email": "https://gozargah.github.io/marzban/",
"alterId": 0,
"flow": null
}
]
}
]
},
"streamSettings": {
"network": "xhttp",
"security": "reality",
"realitySettings": {
"serverName": "pass.seqgen.pro",
"fingerprint": "chrome",
"show": false,
"publicKey": "NsDGc5qCS9reDMokFBPF4VYVf1ayC-Q3NrtG9Ouyskw",
"shortId": "35cefcbf7b206b"
},
"xhttpSettings": {
"headers": {
"Pragma": "no-cache",
"User-Agent": "Mozilla/5.0 (iPhone; CPU iPhone OS 17_4_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148"
},
"mode": "auto",
"host": "pass.seqgen.pro",
"scMaxEachPostBytes": 1000000,
"scMaxConcurrentPosts": 100,
"scMinPostsIntervalMs": 30,
"xPaddingBytes": "100-1000",
"noGRPCHeader": false
}
}
},
{
"protocol": "freedom",
"tag": "direct"
},
{
"protocol": "blackhole",
"tag": "block"
},
{
"protocol": "dns",
"tag": "dns-out"
}
],
"dns": {
"queryStrategy": "UseIPv4",
"servers": [
"https://8.8.8.8/dns-query"
]
},
"routing": {
"domainStrategy": "AsIs",
"rules": [
{
"outboundTag": "dns-out",
"port": "53",
"type": "field"
},
{
"ip": [
"77.88.8.8"
],
"outboundTag": "direct",
"type": "field"
},
{
"domain": [
"oneme.ru",
"max.ru"
],
"outboundTag": "block",
"type": "field"
},
{
"outboundTag": "direct",
"protocol": [
"bittorrent"
],
"type": "field"
},
{
"type": "field",
"domain": [
"domain:gov.ru",
"domain:gosuslugi.ru",
"domain:government.ru",
"domain:kremlin.ru",
"domain:мвд.рф",
"domain:честныйзнак.рф",
"domain:pochta.ru",
"domain:добро.рф",
"domain:dobro.ru",
"domain:ya.ru",
"domain:yandex.ru",
"domain:yandex.net",
"domain:yandex.com",
"domain:yastatic.net",
"domain:yandex-team.ru",
"domain:yandexcloud.net",
"domain:yandexcloud.ru",
"domain:yandexgo.com",
"domain:go.yandex",
"domain:kinopoisk.ru",
"domain:vk.com",
"domain:vk.ru",
"domain:vk.me",
"domain:vkuser.net",
"domain:vk-cdn.net",
"domain:vkvideo.ru",
"domain:userapi.com",
"domain:ok.ru",
"domain:mycdn.me",
"domain:mail.ru",
"domain:imgsmail.ru",
"domain:dzen.ru",
"domain:max.ru",
"domain:rutube.ru",
"domain:ivi.ru",
"domain:okko.tv",
"domain:mts.ru",
"domain:mymts.ru",
"domain:mts-link.ru",
"domain:kion.ru",
"domain:ticketland.ru",
"domain:urentbike.ru",
"domain:beeline.ru",
"domain:megafon.ru",
"domain:tele2.ru",
"domain:t2.ru",
"domain:rostelecom.ru",
"domain:motivtelecom.ru",
"domain:sbermobile.ru",
"domain:t-mobile.ru",
"domain:ozon.ru",
"domain:ozonusercontent.com",
"domain:ozone.ru",
"domain:wildberries.ru",
"domain:wb.ru",
"domain:wbstatic.net",
"domain:avito.ru",
"domain:avito.st",
"domain:megamarket.ru",
"domain:domclick.ru",
"domain:vkusvill.ru",
"domain:auchan.ru",
"domain:metro-cc.ru",
"domain:petrovich.ru",
"domain:av.ru",
"domain:5ka.ru",
"domain:perekrestok.ru",
"domain:magnit.ru",
"domain:dixy.ru",
"domain:lenta.com",
"domain:okeydostavka.ru",
"domain:detsky-mir.ru",
"domain:samokat.ru",
"domain:kuper.ru",
"domain:burgerkingrus.ru",
"domain:vkusnoitochka.ru",
"domain:dodopizza.ru",
"domain:rzd.ru",
"domain:tutu.ru",
"domain:2gis.ru",
"domain:2gis.com",
"domain:taximaxim.ru",
"domain:citydrive.ru",
"domain:citydriveone.onelink.me",
"domain:aeroflot.ru",
"domain:pobeda.aero",
"domain:grandtrain.ru",
"domain:dellin.ru",
"domain:cdek.ru",
"domain:delimobil.ru",
"domain:belkacar.ru",
"domain:s7.ru",
"domain:otello.ru",
"domain:alfabank.ru",
"domain:vtb.ru",
"domain:psbank.ru",
"domain:gazprombank.ru",
"domain:cbr.ru",
"domain:moex.com",
"domain:nspk.ru",
"domain:mironline.ru",
"domain:mtsbank.ru",
"domain:rbc.ru",
"domain:tass.ru",
"domain:ria.ru",
"domain:kp.ru",
"domain:gazeta.ru",
"domain:lenta.ru",
"domain:rambler.ru",
"domain:iz.ru",
"domain:aif.ru",
"domain:rg.ru",
"domain:vedomosti.ru",
"domain:mk.ru",
"domain:kommersant.ru",
"domain:pnp.ru",
"domain:pikabu.ru",
"domain:ixbt.com",
"domain:rt.com",
"domain:1tv.ru",
"domain:ntv.ru",
"domain:smotrim.ru",
"domain:otr-online.ru",
"domain:tvc.ru",
"domain:tv3.ru",
"domain:mir24.tv",
"domain:tnt-online.ru",
"domain:ctc.ru",
"domain:spastv.ru",
"domain:5-tv.ru",
"domain:ren.tv",
"domain:friday.ru",
"domain:domashniy.ru",
"domain:muz-tv.ru",
"domain:tvzvezda.ru",
"domain:matchtv.ru",
"domain:hh.ru",
"domain:gismeteo.ru",
"domain:apteka.ru",
"domain:drom.ru",
"domain:drive2.ru",
"domain:lizaalert.org",
"domain:ruwiki.ru",
"domain:1c.ru",
"domain:1c-bitrix.ru",
"domain:kontur.ru",
"domain:sbis.ru",
"domain:evotor.ru",
"domain:trudvsem.ru",
"domain:starline.ru",
"domain:monitoring.plus",
"domain:csat.ru",
"domain:medsi.ru",
"domain:mamadeti.ru",
"domain:khl.ru"
],
"outboundTag": "direct"
},
{
"type": "field",
"network": "tcp,udp",
"balancerTag": "mb-balancer-2"
}
],
"balancers": [
{
"tag": "mb-balancer-2",
"selector": [
"mb-balancer-2-"
],
"strategy": {
"type": "leastPing"
}
}
]
},
"remarks": "🇩🇪 Германия 👻",
"observatory": {
"subjectSelector": [
"mb-balancer-2-"
],
"probeUrl": "https://www.gstatic.com/generate_204",
"probeInterval": "300s",
"enableConcurrency": true
}
}
""";
void main() async {
final map = jsonDecode(exJson);
final config = XrayConfig.fromJson(map);
final client = VlessClient(
id: '222232-32-3-2-3-23--23-2-3',
email: 'example@test.com',
flow: XtlsFlow.xtlsRprxVision,
);
final inbound = VlessInbound(
port: Port.single(443),
tag: "vless-in",
settings: VlessInboundSettings(clients: [client]),
streamSettings: StreamSettings(
network: StreamNetwork.raw,
security: StreamSecurity.reality,
rawSettings: RawSettings(
header: HttpSettingsHeaders(request: HttpRequest(path: ['/test'])),
),
realitySettings: RealitySettings(
target: "www.google.com",
fingerprint: Fingerprint.ios,
show: false,
xver: 0,
serverNames: ["google.com"],
spiderX: "/test",
password: "password",
shortIds: ["abs"],
),
),
);
final link = VlessShareEntity.fromInbound(inbound, client: client);
print(link);
final outbound = link.toOutbound();
final outbound1 = VlessShareEntity.fromString(
'vless://9cc8aa8f-3930-40c2-a2ed-35a9705122dc@deu-3.wispvpn.online:443?security=reality&type=raw&headerType=&flow=xtls-rprx-vision&path=%2Ffeed&host=vk.com&sni=www.vk.com&fp=edge&pbk=Z8T275uWZ2ReacSASMMEhjGGQU6CtwH_e1NNZnwgnns&sid=ae821ab748a2575f&spx=%2F#%F0%9F%87%A9%F0%9F%87%AA%20%D0%93%D0%B5%D1%80%D0%BC%D0%B0%D0%BD%D0%B8%D1%8F%20%5BDEU-3%5D',
);
print(outbound);
print(outbound1);
final lib = XrayLibCore(
"D:\\projects\\proxywisp_app\\bin\\libs\\xray_sdk.dll",
);
print(lib.version());
// final en = VlessShareEntity.fromString(
// "vless://9cc8aa8f-3930-40c2-a2ed-35a9705122dc@deu-3.24wisp.ru:8090?security=tls&type=ws&headerType=&path=%2F&host=deu-3.24wisp.ru&sni=deu-3.24wisp.ru&fp=#%F0%9F%87%A9%F0%9F%87%AA%20%D0%93%D0%B5%D1%80%D0%BC%D0%B0%D0%BD%D0%B8%D1%8F%20%5BDEU-3%5D",
// );
// final config = XrayConfig(
// log: LogConfig(logLevel: LogLevel.none),
// inbounds: [
// SocksInbound(
// port: Port.single(10802),
// tag: "socks-in",
// listen: "127.0.0.1",
// settings: SocksInboundSettings(udp: true),
// ),
// ],
// outbounds: [en.toOutbound(remark: "out")],
// );
// await lib.startAsync(config, env: {"XRAY_LOCATION_ASSET": "/example"});
// final timeout = await lib.pingConfig(config, [
// 10802,
// ], "https://www.gstatic.com/generate_204");
// print(timeout);
}