bug in net-lookup

Q&A's, tips, howto's
Locked
notbugme
Posts: 5
Joined: Tue Aug 09, 2005 10:43 am

bug in net-lookup

Post by 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.

Code: Select all

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
Posts: 733
Joined: Thu Feb 26, 2004 10:19 pm
Location: The Hague, The Netherlands
Contact:

Post by pjot »

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:
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

newdep
Posts: 2038
Joined: Mon Feb 23, 2004 7:40 pm
Location: Netherlands

Post by newdep »

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
Posts: 5
Joined: Tue Aug 09, 2005 10:43 am

Post by notbugme »

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

Nor standard network commands can handle this format:
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:

Code: Select all

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
Posts: 408
Joined: Sat Jun 04, 2005 4:16 pm
Location: Russia
Contact:

Post by Dmi »

probably, the safe way will be to write something like:

Code: Select all

(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
Posts: 5
Joined: Tue Aug 09, 2005 10:43 am

Post by notbugme »

newdep wrote:Welcome ;-)
Thanks.
newdep wrote: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 instead of gethostbyname when called with "10.41.232.199.in-addr.arpa".

notbugme
Posts: 5
Joined: Tue Aug 09, 2005 10:43 am

Post by notbugme »

Dmi wrote:probably, the safe way will be to write something like:

Code: Select all

(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
Posts: 408
Joined: Sat Jun 04, 2005 4:16 pm
Location: Russia
Contact:

Post by Dmi »

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:

Code: Select all

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

Code: Select all

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
Posts: 408
Joined: Sat Jun 04, 2005 4:16 pm
Location: Russia
Contact:

Post by Dmi »

... 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
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Post by Lutz »

Good suggestion, I implemented an optional 'true' flag which will force hostbyname() even if starting with a number digit:

Code: Select all

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
Posts: 408
Joined: Sat Jun 04, 2005 4:16 pm
Location: Russia
Contact:

Post by Dmi »

Cool!
WBR, Dmi

notbugme
Posts: 5
Joined: Tue Aug 09, 2005 10:43 am

Post by notbugme »

Lutz wrote:Good suggestion, I implemented an optional 'true' flag which will force hostbyname() even if starting with a number digit:

Code: Select all

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
Posts: 733
Joined: Thu Feb 26, 2004 10:19 pm
Location: The Hague, The Netherlands
Contact:

Post by pjot »

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:

Code: Select all

(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

Locked