Lua detects MTU value by Ping command

Lua detects MTU value by Ping command

local function mtuTest(dstIp)
	local tmp, ret, minMtu, maxMtu = 0, 0, 1, 1500

	while true do
		tmp = math.modf((minMtu + maxMtu) / 2)
		ret = os.execute("ping -c 1 -w 1 "..dstIp.." -s "..tmp.." > /dev/null 2>&1")
		if ret == 0 then
			minMtu = tmp
		else
			maxMtu = tmp
		end

		if minMtu + 1 >= maxMtu then
			return minMtu
		end
	end
end

Comments

Popular posts from this blog

Python Receiving and parse JSON Data via UDP protocol

ubus lua client method and event registration code demo/example