Last active
December 23, 2015 07:39
-
-
Save d33tah/6602030 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
description = [[ | |
Connects to an OpenTibia server and prints information such as the server name, | |
uptime, number of players connected, location, website URL, owner data and | |
gameplay features. | |
]] | |
--- | |
-- @output | |
-- PORT STATE SERVICE VERSION | |
-- 7171/tcp open OpenTibia 8.7x | |
-- | opentibia-info: | |
-- | map: | |
-- | name: World.otbm | |
-- | height: 33330 | |
-- | author: Thunder OT | |
-- | width: 33455 | |
-- | owner: | |
-- | name: Thunder OT | |
-- | email: contato@thunderot.com.br | |
-- | players: | |
-- | peak: 468 | |
-- | max: 700 | |
-- | online: 83 | |
-- | serverinfo: | |
-- | uptime: 10h:4m | |
-- | servername: Thunder OT | |
-- | version: 0.4_SVN | |
-- | server: Advanced Forgotten Server | |
-- | location: Brazil | |
-- | ip: 198.27.78.2 | |
-- | url: http://www.thunderot.com.br | |
-- | port: 7171 | |
-- | client: 8.71 | |
-- | npcs: | |
-- | total: 650 | |
-- | monsters: | |
-- |_ total: 52219 | |
author = "Jacek Wielemborek" | |
license = "Same as Nmap--See http://nmap.org/book/man-legal.html" | |
categories = { "default", "discovery", "safe" } | |
portrule = function(host, port) | |
return (port.number == 7171 or port.service == "OpenTibia") | |
and port.protocol == "tcp" | |
and port.state == "open" | |
end | |
-- Formats an uptime string containing a number of seconds. | |
-- E.g. "3670" -> "1h:1m" | |
-- @param uptime number of seconds of uptime | |
-- @return uptime_formatted formatted uptime string (hours and minutes) | |
-- Copied from ventrilo-info.nse. | |
local uptime_str = function(uptime) | |
local uptime_num = tonumber(uptime) | |
if not uptime_num then | |
return uptime | |
end | |
local h = math.floor(uptime_num/3600) | |
local m = math.floor((uptime_num - h*3600)/60) | |
return h .. "h:" .. m .. "m" | |
end | |
action = function(host, port) | |
local output = {} | |
local status, err, response | |
local socket = nmap.new_socket() | |
socket:connect(host.ip, port) | |
status, err = socket:send("\x06\x00\xff\xffinfo") | |
status, response = socket:receive_bytes(0) | |
response = response:sub(response:find("<serverinfo"), response:len()) | |
-- Yes, I do feel sorry about the kittens. | |
for group, body in response:gmatch("<(%w+)(.-)/>") do | |
local created_group = false | |
for k, v in body:gmatch('(%w+)="(.-)"') do | |
if v ~= '' then | |
if not created_group then | |
output[group] = {} | |
created_group = true | |
end | |
if k ~= "uptime" then | |
output[group][k] = v | |
else | |
output[group][k] = uptime_str(v) | |
end | |
end | |
end | |
end | |
return output | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment