PtokaX forum

Lua 5.3/5.2/5.1 Scripts (for PtokaX 0.4.0.0 and newer) => Finished Scripts => Topic started by: mars on 03 June, 2012, 18:09:16

Title: DnsLookup
Post by: mars on 03 June, 2012, 18:09:16
hi
is there a dnslookup script for ptokax
i did a search but could not find anything

thanks
Title: Re: DnsLookup
Post by: Nando on 03 June, 2012, 18:44:32
yes there is
but not here xD
Title: Re: DnsLookup
Post by: PPK on 03 June, 2012, 20:18:19
Simple DNS lookup script.
Require LuaSocket (http://forum.ptokax.org/index.php?topic=8852.0).
Use it with command !dnslookup hostname 8)
require "socket"

function ChatArrival(tUser, sData)
   if Core.GetUserValue(tUser, 11) == true and string.find(SetMan.GetString(29), string.sub(sData, 4+string.len(tUser.sNick), 4+string.len(tUser.sNick)), 1, true) then
      if string.sub(sData, 5+string.len(tUser.sNick), 14+string.len(tUser.sNick), true) ~= "dnslookup " then
         return false
      end

      dnstolookup = string.sub(sData, 15+string.len(tUser.sNick), sData:len()-1, true)

      if dnstolookup:len() == 0 then
         Core.SendToUser(tUser, "<"..Core.GetHubSecAlias().."> Error, no DNS specified!|")
         return true
      end

      result, msg = socket.dns.toip(dnstolookup)
      if result then
         Core.SendToUser(tUser, "<"..Core.GetHubSecAlias().."> "..dnstolookup.." have IP address: "..result)
      else
         Core.SendToUser(tUser, "<"..Core.GetHubSecAlias().."> DNS lookup failed because: "..msg)
      end

      return true
   end
end
Title: Re: DnsLookup
Post by: mars on 05 June, 2012, 19:23:25
Thank you :)

However I did not explain what I was looking for properly.

What I am trying to do is have a script that checks when a user logs into the hub and does an NSLookUp on his IP address (using a name server that I can provide). If lookup returns a DNS entry then its ok, but if it comes back empty it must warn or kick the user.

This is for a hub running on a private network with its own nameserver :)
Title: Re: DnsLookup
Post by: PPK on 09 June, 2012, 23:14:20
Sorry but i don't see any good reason for script like that ::)
Title: Re: DnsLookup
Post by: mars on 12 June, 2012, 10:40:06
Hi
as we have our own wireless network with about 4000 people it is very important for us that the client details is upto date and he must have a dns and ips on the network before he can join dc
The script will check his dns and will allow him on the network if all his details is upto date
This will save us the time to check each persons details

thanks
Title: Re: DnsLookup
Post by: PPK on 12 June, 2012, 15:04:57
Huh, now it is getting really complicated.
I can create simple script that will use user ip to resolve dns and disconnect user without dns. I can't do that with dns server you provide, it will use os dns settings because i don't know any library with support for custom dns servers  ::)
Title: Re: DnsLookup
Post by: mars on 12 June, 2012, 19:06:13
the os dns will work fine

thanks
Title: Re: DnsLookup
Post by: PPK on 13 June, 2012, 14:47:53
Require LuaSocket (http://forum.ptokax.org/index.php?topic=8852.0).
require "socket"

function UserConnected(tUser)
   if socket.dns.tohostname(tUser.sIP) == nil then
      Core.SendToUser(tUser, "<"..Core.GetHubSecAlias().."> Sorry, we don't accept users without updated DNS!|")
      Core.Disconnect(tUser)

      return true
   end
end
Title: Re: DnsLookup
Post by: mars on 13 June, 2012, 17:17:42
Thanks
Title: Re: DnsLookup
Post by: mars on 04 September, 2012, 20:31:11
Hi PPK

Could you please explain to me how to install LuaSocket on a Windows PC running PtokaX 4.2.0. I've tried extracting the archive into PtokaX/scripts, but when I try and run it it tells me there are missing files.

Thanks
Title: Re: DnsLookup
Post by: ATAG on 07 September, 2012, 13:32:59
Get a correct version of PxLuaSocket and extract it to the libs folder (you have to create it manually).
maybe... (http://forum.ptokax.org/index.php?action=tpmod;dl=cat50)

Title: Re: DnsLookup
Post by: mars on 09 September, 2012, 17:01:00
thanks
any more help would be apreciated as we are still having problems with errors in windows 7
Title: Re: DnsLookup
Post by: ATAG on 10 September, 2012, 09:34:32
Sorry, i was wrong.

Newer libs are here (http://forum.ptokax.org/index.php?topic=8852#msg81265).
Title: Re: DnsLookup
Post by: mars on 18 September, 2012, 19:28:19
Quote from: ATAG on 10 September, 2012, 09:34:32
Sorry, i was wrong.

Newer libs are here (http://forum.ptokax.org/index.php?topic=8852#msg81265).

Hi there

I extracted the new libs you provides into /PtokaX/scripts/libs, and put the dnslookup.lua script into the /PtokaX/scripts folder. When attempting to start the dnslookup script, I get the following error:

[07:26:12 PM] Syntax C:\Users\mars\Desktop\ptokaX\scripts\dns.lua:1: module 'socket' not found:
   no field package.preload['socket']
   no file 'C:\Users\mars\Desktop\PtokaX\scripts\libs'
   no file 'C:\Users\mars\Desktop\PtokaX\scripts\libs'

Any help would be appreciated.

Thanks
Title: Re: DnsLookup
Post by: the-master on 19 September, 2012, 18:09:44
is the hub on linux or windows?
Title: Re: DnsLookup
Post by: mars on 19 September, 2012, 20:27:33
windows 7
Title: Re: DnsLookup
Post by: the-master on 20 September, 2012, 18:23:42
You're right, runs on Xp, but not on win7 :-(
Title: Re: DnsLookup
Post by: ATAG on 21 September, 2012, 16:01:03
Try to extract the whole LuaSocket-2.0.2.7z into "PtokaX\libs".

Quote[15:59:49] No syntax errors in script file dns.lua
[15:59:49] Script started.

(tested on Win7 x64 & 64 bit Px)
Title: Re: DnsLookup
Post by: mars on 21 September, 2012, 19:33:50
ATAG: I have tried extracting the entire LuaSocket-2.0.2.7z into PtokaX\libs directory and PtokaX\scripts\libs directory, but still get the same problem.

Can you perhaps explain what you did to test it in more detail?

Thanks
Title: Re: DnsLookup
Post by: ATAG on 21 September, 2012, 21:27:34
It seems like x86 version doesn't work for me (too)...

Quote[21:26:51] Syntax D:\PtokaX\libs\socket.lua:18: attempt to index local 'socket' (a boolean value)

It returns only a true boolean (instead of userdata type), ask PPK for help!
Title: Re: DnsLookup
Post by: mars on 21 September, 2012, 22:05:42
Hi PPK

can you help
Title: Re: DnsLookup
Post by: PPK on 23 September, 2012, 23:20:50
WorksForMe?
Code (Testing script) Select

require "socket"
require "mime"

Core.SendToOps("PtokaX version: "..Core.Version
               .."\nPtokaX build: "..Core.BuildNumber
               .."\nLua version: ".._VERSION

               .."\n\nLoaded Lua libraries:\n"

               .."\nLuaSocket version: "..socket._VERSION
               .."\nLuaMime version: "..mime._VERSION
            )


With stable PtokaX http://www.PtokaX.org/files/0.4.2.0.7z and correct LuaSocket lib http://www.PtokaX.org/files/Libs-240/LuaSocket-2.0.2.7z
Quote from: Result[2012-09-23 23:08:34] PtokaX version: 0.4.2.0
PtokaX build: 241
Lua version: Lua 5.1

Loaded Lua libraries:

LuaSocket version: LuaSocket 2.0.2
LuaMime version: MIME 1.0.2

With testing PtokaX with Lua 5.1.5 http://www.PtokaX.org/files/0.4.2.0b401-Lua5.1.5.7z and correct LuaSocket lib http://www.PtokaX.org/files/Libs-376/LuaSocket-2.0.2.7z

Quote from: Result[2012-09-23 23:09:44] PtokaX version: 0.4.2.0
PtokaX build: 401
Lua version: Lua 5.1

Loaded Lua libraries:

LuaSocket version: LuaSocket 2.0.2
LuaMime version: MIME 1.0.2

With testing PtokaX with Lua 5.2.1 http://www.PtokaX.org/files/0.4.2.0b401-Lua5.2.1.7z and correct LuaSocket lib http://www.PtokaX.org/files/Libs-376/LuaSocket-2.0.2.7z

Quote from: Result[2012-09-23 23:10:24] PtokaX version: 0.4.2.0
PtokaX build: 401
Lua version: Lua 5.2

Loaded Lua libraries:

LuaSocket version: LuaSocket 2.0.2
LuaMime version: MIME 1.0.2
Title: Re: DnsLookup
Post by: ATAG on 24 September, 2012, 00:55:13
Quote from: PPK on 23 September, 2012, 23:20:50
WorksForMe?
I think, you are the only one, who can find some logic between versions of libs and px builds. We are mortals =)

Anyway i've tested same versions on x64 win7... but x86 doesn't work for me. Tomorrow i'll try on x32 machine too :)
Title: Re: DnsLookup
Post by: mars on 24 September, 2012, 01:37:12

WorksForMe?

can you explain more in detail how you did it in windows 7 as we are still having problems
Title: Re: DnsLookup
Post by: mars on 28 September, 2012, 17:47:05
Anyway i've tested same versions on x64 win7... but x86 doesn't work for me. Tomorrow i'll try on x32 machine too :)


Hi any news yet
Title: Re: DnsLookup
Post by: PPK on 28 September, 2012, 18:02:07
Quote from: ATAG on 24 September, 2012, 00:55:13
I think, you are the only one, who can find some logic between versions of libs and px builds. We are mortals =)
It is simple, when you use stable PtokaX then you have build 241 and you need libs for 240 and higher. When you are using testing PtokaX build 376 or higher then you need libs for 376 and higher.
In future probably this mess will be fixed, because libs for build 376 and higher use smart loader. They are not compiled against exact PXLua.dll/PXLua-x64.dll version, they simply search pxlua lib for needed lua functions and as long as PXLua.dll/PXLua-x64.dll contains them then they load and work.
Quote from: mars on 24 September, 2012, 01:37:12
can you explain more in detail how you did it in windows 7 as we are still having problems
I'm downloaded http://www.PtokaX.org/files/0.4.2.0b401-Lua5.1.5.7z and unpacked to e:\PtokaX\ then i'm downloaded http://www.PtokaX.org/files/Libs-376/LuaSocket-2.0.2.7z and unpacked to e:\PtokaX\libs\
Then i'm copied my cfg dir to e:\PtokaX\, added testing script to e:\PtokaX\scripts\, started PtokaX, connected with client and run script  ::)
Title: Re: DnsLookup
Post by: mars on 29 September, 2012, 13:37:30
Quote from: PPK on 28 September, 2012, 18:02:07I'm downloaded http://www.PtokaX.org/files/0.4.2.0b401-Lua5.1.5.7z and unpacked to e:\PtokaX\ then i'm downloaded http://www.PtokaX.org/files/Libs-376/LuaSocket-2.0.2.7z and unpacked to e:\PtokaX\libs\
Then i'm copied my cfg dir to e:\PtokaX\, added testing script to e:\PtokaX\scripts\, started PtokaX, connected with client and run script  ::)
Hi PPK

Thanks for the help but we still have the same problem. We downloaded the ptokaX version you linked and extracted it to C:\ptokaX. We then downloaded LuaSocket above and extracted to C:\ptokaX\libs. We used a blank cfg folder. Then we run ptokaX exe (32 or 64-bit) and go to the Scripts tab to add the script. As soon as we try to run any script that starts with (require "socket") we get the following error:

[01:30:15 PM] Syntax C:\ptokaX\scripts\test.lua:1: module 'socket' not found:
   no field package.preload['socket']

This is on Windows 7 64-bit.
Title: Re: DnsLookup
Post by: mars on 29 September, 2012, 14:12:16
Some progress!

Visiting the LuaSocket installation homepage, I tried adding the following to my Win7 environmental variables under user variables:

LUA_CPATH=C:\PtokaX\libs\?.lua;?.lua

LUA_PATH=C:\PtokaX\libs\?.dll;?.dll

Now when I try to run the scripts with require "socket" in I get the following windows error box:

C:\PtokaX\libs\socket.lua is either not designed to run on Windows or it contains an error.

Any help?
Title: Re: DnsLookup
Post by: ATAG on 29 September, 2012, 17:31:55
Ok, it works now!

QuotePtokaX version: 0.4.2.0
PtokaX build: 241
Lua version: Lua 5.1

Loaded Lua libraries:

LuaSocket version: LuaSocket 2.0.2
LuaMime version: MIME 1.0.2

You have to change the "require" to:

require "pxluasocket"
require "pxmime"


I hope it helps...
Title: Re: DnsLookup
Post by: PPK on 29 September, 2012, 18:01:17
Wrong. You must require socket and mime to get this thing working correctly. When you directly require dlls, then it will not work as it should because big part of luasocket is in scripts (socket.lua, mime.lua and others that are loaded by these)  ::)
Title: Re: DnsLookup
Post by: ATAG on 29 September, 2012, 20:27:40
Ok, i've found the solution  ::)

There is a "scripts" folder in libs with some lua script. We have to copy the scripts to the parent directory (PtokaX\libs) and then it works fine.

(http://kepfeltoltes.hu/thumb/120929/1248261250pxsocket_www.kepfeltoltes.hu_.png) (http://kepfeltoltes.hu/view/120929/1248261250pxsocket_www.kepfeltoltes.hu_.png)
Title: Re: DnsLookup
Post by: mars on 30 September, 2012, 09:46:41
Quote from: ATAG on 29 September, 2012, 20:27:40
Ok, i've found the solution  ::)

There is a "scripts" folder in libs with some lua script. We have to copy the scripts to the parent directory (PtokaX\libs) and then it works fine.

(http://kepfeltoltes.hu/thumb/120929/1248261250pxsocket_www.kepfeltoltes.hu_.png) (http://kepfeltoltes.hu/view/120929/1248261250pxsocket_www.kepfeltoltes.hu_.png)

Thank you!

While this still did not solve my problem, I tried it on 2 other PCs (Win7 64) and it now seems to work on both. I tested PPKs first dnslookup script and it ran with no errors, and allowed me to run !dnslookup from the client.

A big thanks to both of you :)

Now just one other small question about the second DNS script that PPK posted: is it possible that before kicking someone with a "nil" dnslookup, is it possible to first check another DNS? Why I ask is that sometimes our private DNS server goes down so no one has DNS, and then I do not want the script to kick everyone.

So something like this:

1 - Check DNS of IP x.x.x.x
2 - If (1) returns valid DNS, check IP of sUser
3 - If (2) returns nil value, kick sUser and send message to Ops

Is something like this possible?
Title: Re: DnsLookup
Post by: mars on 02 October, 2012, 16:23:09
Hi PPK

After many problems we finally got LuaSocket and your DNS scripts to run on out hub, but now we have another problem.

When the client runs the dnslookup, it does not use the OS DNS server (the one that is specified in TCP/IP settings). Instead it only returns the computer name that is set in Windows. This means that even if the users did not update their DNS details on out database they will not be kicked by the script because it will always return their computer name.

Is there someway to specify that the script used the OS DNS instead of just the computer name?

Thanks