summaryrefslogtreecommitdiffhomepage
path: root/libs/luanet/src/test.lua
blob: 713836b55a2077c5574a6a001a3ab973ebd9c208 (plain)
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#!/usr/bin/lua

print("luanet test")
local luanet = require("luanet")

print("sleeping 4 secs")
luanet.sleep(4)

print("---ifconfig---\n")
print("set ip wlan0 -> 192.168.1.2")
print(luanet.ifc_setip("wlan0", "192.168.1.2"))
print("set ip wlan0:1 -> 192.168.2.2")
print(luanet.ifc_setip("wlan0:1", "192.168.2.2"))
print("set mtu wlan0 -> 1400")
print(luanet.ifc_setmtu("wlan0", "1400"))
--print("set down wlan0 ->")
--print(luanet.ifc_down("wlan0"))
--print("set up wlan0 ->")
--print(luanet.ifc_up("wlan0"))
local devs = luanet.ifc_getall()
for i,v in pairs(devs) do
	print("\ndev -> "..i)
	print(devs[i].ip)
	print(devs[i].netmask)
	print(devs[i].broadaddr)
	print(devs[i].mac)
	print(devs[i].mtu)
	print(devs[i].up)
end


print("\n\n---bridge---\n")
print("add bridge br-test ->")
print(luanet.bridge_new("br-test"))

print("add wlan0 to br-test ->")
print(luanet.bridge_addif("br-test", "wlan0"))

print("listing bridges")
local brs = luanet.bridge_getall()
if brs then
	for i,v in pairs(brs) do
		print(i)
		for j,k in pairs(v) do
			print(j.."->"..k)
		end
	end
end
print("del wlan0 from br-test ->")
print(luanet.bridge_delif("br-test", "wlan0"))

print("del bridge br-test ->")
print(luanet.bridge_del("br-test"))


print("\n\n---wifi---\n")
print("set wlan0 essid test123")
print(luanet.iwc_set_essid("wlan0", "test123"))
print("set wifi channel to 3")
print(luanet.iwc_set_channel("wlan0", 3))
print("set wifi to managed")
print(luanet.iwc_set_mode("wlan0", "managed"))
print("\nget all wifi devices")
local wifidevs = luanet.iwc_getall()
if wifidevs then
	for i,v in pairs(wifidevs) do
		print(i)
		for j,k in pairs(v) do
			print("  "..j.."->"..k)
		end
	end
end
local scan = luanet.iwc_scan("wlan0")
print("\nscanning wifi on wlan0")
if scan then
	for i,v in pairs(scan) do
		print("\n"..i)
		print("  mac -> "..v.addr)
		print("  frequency -> "..v.frequency)
		print("  channel -> "..v.channel)
		print("  mode -> "..v.mode)
		print("  essid -> "..v.essid)
		print("  key -> "..v.key)
		print("  wpa1gcipher -> "..(v.wpa1gcipher or ""))
		print("  wpa1pcipher -> "..(v.wpa1pcipher or ""))
		print("  wpa1auth -> "..(v.wpa1auth or ""))
		print("  wpa2gcipher -> "..(v.wpa2gcipher or ""))
		print("  wpa2pcipher -> "..(v.wpa2pcipher or ""))
		print("  wpa2auth -> "..(v.wpa2auth or ""))
		print("  bitrates")
		for j,k in ipairs(v.bitrates) do
			--print(j.."->"..k)
		end
	end
end


print("\n\n---vlan---\n")
print("add wlan0 to vlan0")
print(luanet.vlan_add("wlan0", 0));
print("add wlan0 to vlan1")
print(luanet.vlan_add("wlan0", 1));
print("del wlan0 from all vlans")
print(luanet.vlan_del("wlan0.0"));
print("add wlan0 to vlan6")
print(luanet.vlan_add("wlan0", 6));
local vlans = luanet.vlan_getall()
if vlans then
	for i,v in ipairs(vlans) do
		print(i.."->"..v)
	end
end


print("\n\n---df---\n")

print("getting disc usage")
local discs = luanet.df()
if discs then
	for i,v in ipairs(discs) do
		print(i.."->")
		for k,l in pairs(v) do
			print("  "..k.."->"..l)
		end
	end
end


print("\n\n---b64---\n")
print("test2 -->"..(luanet.b64_encode("test2") or "fail"))
print("dGVzdDI= -->"..(luanet.b64_decode("dGVzdDI=") or "fail"))