This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

dnslookup not playing nice

Old posts that have not been replied to for several years.
Locked
s
spock
Master
Posts: 319
Joined: Thu Dec 12, 2002 8:40 pm

dnslookup not playing nice

Post by spock »

Im trying to write a script to do the following task:

<me>.ip nick
<bot> this.is.the.host.net 123.123.123.123

its a dcc command, and it returns host and ip of nick.

Code: Select all

bind dcc n|n ip dcc:ip
proc dcc:ip {handle idx nick} {
set host [lindex [split [getchanhost $nick] @] end] 
set lookup [dnslookup $host lookup]
putdcc $idx "$host $lookup"
}

proc lookup { ip hostname status } {
  return $ip
}
now, the problem is:

when i .ip nick, it returns
<bot> this.is.the.host.net

in other words, doesnt return ip.
strange thing is, second time around .ip samenick, it works like i want it to
<bot> this.is.the.host.net 123.123.123.123

any ideas on where i [censored] up ?
photon?
e
egghead
Master
Posts: 481
Joined: Mon Oct 29, 2001 8:00 pm
Contact:

Re: dnslookup not playing nice

Post by egghead »

spock wrote:Im trying to write a script to do the following task:

<me>.ip nick
<bot> this.is.the.host.net 123.123.123.123


when i .ip nick, it returns
<bot> this.is.the.host.net

in other words, doesnt return ip.
strange thing is, second time around .ip samenick, it works like i want it to
<bot> this.is.the.host.net 123.123.123.123

any ideas on where i **** up ?
dnslookup is asynchronous. It returns immediately if it has the lookup info cached. This actually is the way you use the proc. That is why first you don't get the result and a few seconds later the proc returns the result from cache.

Otherwise you will need to call a proc after the dnslookup has completed.
Read doc/tcl-commands.doc for more info on how to do that.

By the way, there are scripts that do exactly what you want.
s
spock
Master
Posts: 319
Joined: Thu Dec 12, 2002 8:40 pm

Post by spock »

i heard bmw makes cars now. maybe fiat should stop because of this :)

thanks
photon?
User avatar
caesar
Mint Rubber
Posts: 3778
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

Code: Select all

bind dcc n|n dns2 dcc:dns2

proc dcc:dns2 {handle idx nick} {
  global ip
  set host [lindex [split [getchanhost $nick] @] end]
  set lookup [dnslookup $host lookup]
  putdcc $idx "Result: $host $lookup"
}

proc lookup { ip hostname status } {
return $ip
}
This is working fine to me.
Result: caesar.u2.something.ro 192.168.108.55
Once the game is over, the king and the pawn go back in the same box.
p
ppslim
Revered One
Posts: 3914
Joined: Sun Sep 23, 2001 8:00 pm
Location: Liverpool, England

Post by ppslim »

caesar wrote:

Code: Select all

bind dcc n|n dns2 dcc:dns2

proc dcc:dns2 {handle idx nick} {
  global ip
  set host [lindex [split [getchanhost $nick] @] end]
  set lookup [dnslookup $host lookup]
  putdcc $idx "Result: $host $lookup"
}

proc lookup { ip hostname status } {
return $ip
}
This is working fine to me.
Result: caesar.u2.something.ro 192.168.108.55
This is still incorrect, and only works if the information is cached.

Try doing it on a few nicks, and you may find it fails on some.

What the command does is this.

1: You do a lookup on the hostname, or IP. Along with it, you specify a command and any argument you want ot pass to it.

2: If the data is allready cached, return this cached information.

3: Do a lookup if needed

4: If details are not cached, cache them for later.

5: Call the command specified with the details.

6: The command should then continue where the other script left off.

With your "return $ip", it doesn't make it return the data to the previously runnign script.

Asycronous means, that the bot doesn't feeze while it obtains the data, and is able to continue, to prevent possible PING timeouts.

It simply continues with the script.

IOnce the result of the DNS is in, if it be 1 second, or 1 hour, the command will then be called.

The command with the return code in, is no more usful that the original post, as it doesn't return to the original code.
Locked