newLISP Fan Club

Forum => newLISP in the real world => Topic started by: notbugme on August 09, 2005, 04:08:43 AM

Title: bug in net-lookup
Post by: notbugme on August 09, 2005, 04:08:43 AM
The following code suggests that net-lookup is not capable of handling queries such as 10.41.232.199.in-addr.arpa. It appears newLISP gets confused by the query starting with an IP address. This feature is important to me because I would like to be able to check for an IP's address in a DNS BL -- ie check whether 10.41.232.199.relays.ordb.org returns 127.0.0.2 to indicate the address is listed as an open relay.


newLISP v.8.6.0 on Win32 MinGW, execute 'newlisp -h' for more info.

> (net-lookup "gnu.org")                    ;; right
"199.232.41.10"
> (net-lookup "199.232.41.10")              ;; right
"gnu.org"
> (net-lookup "10.41.232.199.in-addr.arpa") ;; wrong
nil
> (net-lookup "10.41.232.199")              ;; right
nil
> (exit)
Title:
Post by: pjot on August 09, 2005, 06:15:17 AM
A (net-lookup) the way you want it is not possible with newLisp since it expects a genuine IP address as argument.



This is not a bug since it is no feature of newLisp anyway.



Nor standard network commands can handle this format:
Quote
c:Scripts>ping 10.41.232.199.relays.ordb.org

Unknown host 10.41.232.199.relays.ordb.org.



c:Scripts>tracert 10.41.232.199.relays.ordb.org

Unable to resolve target system name 10.41.232.199.relays.ordb.org.


What exactly is it you need? You want to check the source IP address to avoid spam? Maybe this can be achieved in another way, e.g. by sending a HTTP POST request with newLisp to the http://ordb.org/submit/ website.



Peter
Title:
Post by: newdep on August 09, 2005, 06:27:05 AM
Welcome ;-)



net-lookup does this ->

Returns a hostname string from str-ip-number in IP dot format or returns the IP number in dot format from str-hostname.



10.41.232.199.in-addr.arpa is not wrong its a DNS notation!



If you want to query the DNS database on any DNS server you better build your own DNS-lookup tools or use tools like dnslookup or dig (thats linux)



Regards,

Norman.
Title:
Post by: notbugme on August 09, 2005, 07:53:16 AM
Quote from: "pjot"This is not a bug since it is no feature of newLisp anyway.



Nor standard network commands can handle this format:
Quote
c:Scripts>ping 10.41.232.199.relays.ordb.org

Unknown host 10.41.232.199.relays.ordb.org.


ORDB does not list that address as an open relay. Try 216.16.84.66.sbl-xbl.spamhaus.org:
C:>ping 216.16.84.66.sbl-xbl.spamhaus.org

Pinging 216.16.84.66.sbl-xbl.spamhaus.org [127.0.0.2] with 32 bytes of data:

Reply from 127.0.0.2: bytes=32 time<10ms TTL=128
Reply from 127.0.0.2: bytes=32 time<10ms TTL=128
Reply from 127.0.0.2: bytes=32 time<10ms TTL=128
Title:
Post by: Dmi on August 09, 2005, 07:56:15 AM
probably, the safe way will be to write something like:
(define (great-net-lookup s)
  (let (l nil)
    (net-lookup
      (if (set 'l (match '(? ? ? ? "in-addr" "arpa") (parse s ".")))
        (join (reverse l) "."))
        s)))

so:

> (great-net-lookup "1.2.3.4.in-addr.arpa")

"crtntx1-ar9-4-3-002-001.crtntx1.dsl-verizon.net"

> (great-net-lookup "crtntx1-ar9-4-3-002-001.crtntx1.dsl-verizon.net")

"4.3.2.1"

> (great-net-lookup "4.3.2.1")

"crtntx1-ar9-4-3-002-001.crtntx1.dsl-verizon.net"
Title:
Post by: notbugme on August 09, 2005, 08:31:18 AM
Quote from: "newdep"Welcome ;-)
Thanks.


Quote from: "newdep"net-lookup does this ->

Returns a hostname string from str-ip-number in IP dot format or returns the IP number in dot format from str-hostname.

That was what I meant by net-lookup getting confused. I believe that in order for it to determine which way it acts anytime it is called it examines the argument and wrongly calls the gethostbyaddr (//http) instead of gethostbyname (//http) when called with  "10.41.232.199.in-addr.arpa".
Title:
Post by: notbugme on August 09, 2005, 08:40:19 AM
Quote from: "Dmi"probably, the safe way will be to write something like:
(define (great-net-lookup s)
  (let (l nil)
    (net-lookup
      (if (set 'l (match '(? ? ? ? "in-addr" "arpa") (parse s ".")))
        (join (reverse l) "."))
        s)))

That is a smart way to handle "*.*.*.*.in-addr.arpa" but it does not work for doing a DNS BL query -- eg "216.16.84.66.sbl-xbl.spamhaus.org".
Title:
Post by: Dmi on August 09, 2005, 09:09:11 AM
Heh! ;-)

After a looooong time bind9 linked to root servers found "216.16.84.66.sbl-xbl.spamhaus.org" as well as 216.16.84.66



so I can see, that:
dmi@dc$ newlisp
> (net-lookup "216.16.84.66.sbl-xbl.spamhaus.org")
"AdrianDHCP-66.216-16-84.iw.net"
> (net-lookup "AdrianDHCP-66.216-16-84.iw.net")
"216.16.84.66"


and
dmi@dc$ ping 216.16.84.66.sbl-xbl.spamhaus.org
PING 216.16.84.66.sbl-xbl.spamhaus.org (127.0.0.2): 56 data bytes
64 bytes from 127.0.0.2: icmp_seq=0 ttl=64 time=0.1 ms
64 bytes from 127.0.0.2: icmp_seq=1 ttl=64 time=0.0 ms


so, I think, newLisp is really wrong here...
Title:
Post by: Dmi on August 09, 2005, 09:30:03 AM
... and, btw, I think that flip-flop nature of net-lookup is not handy for coding either:

IMHO usualy we need explicitly IP or explicitly fqdn, but not conversion of something to someting.



If Lutz will correct net-lookup behavior, it would be nice to have second optional parameter: normal or reverse lookup. And autosence of ip/name in either case ;-)
Title:
Post by: Lutz on August 09, 2005, 10:36:26 AM
Good suggestion, I implemented an optional 'true' flag which will force hostbyname() even if starting with a number digit:



newLISP v.8.6.2 on OSX UTF-8, execute 'newlisp -h' for more info.

> (net-lookup "216.16.84.66.sbl-xbl.spamhaus.org" true)
"127.0.0.2"
>


This will show up in 8.6.2



Lutz



ps: and a welcome to 'notbugme'
Title:
Post by: Dmi on August 09, 2005, 11:37:17 AM
Cool!
Title:
Post by: notbugme on August 09, 2005, 01:11:57 PM
Quote from: "Lutz"Good suggestion, I implemented an optional 'true' flag which will force hostbyname() even if starting with a number digit:



newLISP v.8.6.2 on OSX UTF-8, execute 'newlisp -h' for more info.

> (net-lookup "216.16.84.66.sbl-xbl.spamhaus.org" true)
"127.0.0.2"
>


This will show up in 8.6.2



Lutz



ps: and a welcome to 'notbugme'

Great!
Title:
Post by: pjot on August 09, 2005, 01:15:07 PM
Quote
ORDB does not list that address as an open relay. Try 216.16.84.66.sbl-xbl.spamhaus.org:


Ah well, that works indeed with a ping. In that case you can also say:



(set 'result (exec "ping 216.16.84.66.sbl-xbl.spamhaus.org"))
(if (> (length result) 1)
  (println "Address exists")
  (println "Not found!")
)


But with 8.6.2 it will be solved anyway.



Peter