This repository has been archived by the owner on Jun 3, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
example.py
executable file
·56 lines (46 loc) · 1.9 KB
/
example.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#! /usr/bin/env python3
import cli
from mesh import *
""" The example configuration also my personal private network configuration.
"""
def gen_net(tmp_key: bool, mock_net: bool):
net = Network(mock_net)
# define hosts and connections between them
net.add_host("bj", "39.96.60.177", cli.get_key("bj", tmp_key))
net.add_host("hk", "47.244.57.178", cli.get_key("hk", tmp_key))
net.connect("bj", "hk", "10.56.1.0/30", 45677)
clients_conf = [
("iPhone", "10.56.200.16/30", 45678),
("Macbook", "10.56.200.20/30", 45679),
("xzw", "10.56.200.24/30", 45680),
("lyh", "10.56.200.28/30", 45681),
("zhy", "10.56.200.32/30", 45682),
("qyx", "10.56.200.36/30", 45683),
("zys", "10.56.200.40/30", 45684),
("iPad", "10.56.200.44/30", 45685),
("lby", "10.56.200.48/30", 45686),
("zd-mac", "10.56.200.52/30", 45687),
("zd-phone", "10.56.200.56/30", 45688),
("zd-3", "10.56.200.60/30", 45689),
("zd-4", "10.56.200.64/30", 45690),
("gram", "10.56.200.68/30", 45691),
("wmd", "10.56.200.72/30", 45692),
]
for c, cidr, port in clients_conf:
net.add_host(c, "", cli.get_key(c, tmp_key))
net.connect(c, "bj", cidr, port)
# define the ipset bundles used to match the destination ip later
chinaip = IPSet("chinaip", chinaip_list())
privateip = IPSet("privateip", privateip_list())
chinaip_bundle = IPSetBundle(match=[chinaip], not_match=[])
nonchinaip_bundle = IPSetBundle(match=[], not_match=[chinaip, privateip])
# add policy routing rules
net.output_to_nat_gateway(nonchinaip_bundle, "bj", "hk")
for c, _, _ in clients_conf:
net.output_to_nat_gateway(chinaip_bundle, c, "bj")
net.output_to_nat_gateway(nonchinaip_bundle, c, "hk")
# freedns
net.add_freedns("bj")
return net
if __name__ == "__main__":
cli.mesh_main(gen_net)