bug in net-lookup

Started by notbugme, August 09, 2005, 04:08:43 AM

Previous topic - Next topic

notbugme

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)

pjot

#1
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/">http://ordb.org/submit/ website.



Peter

newdep

#2
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.
-- (define? (Cornflakes))

notbugme

#3
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

Dmi

#4
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"
WBR, Dmi

notbugme

#5
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 http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winsock/winsock/gethostbyaddr_2.asp">gethostbyaddr instead of http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winsock/winsock/gethostbyname_2.asp">gethostbyname when called with  "10.41.232.199.in-addr.arpa".

notbugme

#6
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".

Dmi

#7
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...
WBR, Dmi

Dmi

#8
... 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 ;-)
WBR, Dmi

Lutz

#9
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'

Dmi

#10
Cool!
WBR, Dmi

notbugme

#11
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!

pjot

#12
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