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.

dns reverse ip ?

Old posts that have not been replied to for several years.
O
Ofloo
Owner
Posts: 953
Joined: Tue May 13, 2003 1:37 am
Location: Belguim
Contact:

dns reverse ip ?

Post by Ofloo »

how do i resolve the reverse lookup to an ip ?

Code: Select all

bind PUB n !test test:pub 

proc test:pub {nick uhost hand chan arg} {
global botnick
  putserv "whois $botnick"
}

bind RAW - 378 test:raw

proc test:raw {from key arg} {
global botnick
  set bothost [join [lrange $arg 0 end]]
  set sbothost [lindex [split $bothost @] 1]
  putlog "$sbothost"
}
XplaiN but think of me as stupid
r
rolandguy
Voice
Posts: 25
Joined: Wed Aug 13, 2003 1:50 pm

Post by rolandguy »

probably the easiest way to do this is to exec a shell command such as dig. for exampe:

set rhost [exec dig -x 127.0.0.1 +short]

hope this helps...

roland
O
Ofloo
Owner
Posts: 953
Joined: Tue May 13, 2003 1:37 am
Location: Belguim
Contact:

Post by Ofloo »

sorry hehe to late no shell by the way this will work on win and linux i gues

also works on irc servers with encrypted ips

and on normal servers on normalservers change raw 378 to 311

it caches the ip on connnect ;) so if you wana use it look at !test how i used it ideal self lookup true irc ;)

yes i know sorry it just popped in my head later on .. :/


** If any one can improve this script plz do i want to expand my knowledge

Code: Select all

bind EVNT - init-server conn:init 

proc conn:init init-server { 
  putserv "whois $botnick" 
}

bind RAW - 378 reslove:raw

proc reslove:raw {from key arg} {
global botnick
  set bothost [join [lrange $arg 0 end]]
  set sbothost [lindex [split $bothost @] 1]
  set nslookup [dnslookup $sbothost reslove:ipaddress]
}

proc reslove:ipaddress {ipaddres hostname status} {
  set wfile [open "MyIP" "w"]
  puts $wfile $ipaddres
  close $wfile
  putlog "Succesfully cached ip: \002$ipaddres\002."
}

proc MyIP {} {
  set rfile [open "MyIP" "r"] 
  set MyIP [read $rfile]
  close $rfile 
  return $MyIP
}

bind pub - !test test:pub 

proc test:pub {nick uhost handle chan arg} {
  putserv "notice $nick :[MyIP]"
}
XplaiN but think of me as stupid
r
rolandguy
Voice
Posts: 25
Joined: Wed Aug 13, 2003 1:50 pm

Post by rolandguy »

:/ am a bit confused here...you're using a raw 378 numeric...what IRCd?

are you just wanting the bots hotname? or others as well? if the IPs are masked, you won't get dnslookup to work :/ maybe I'm just not getting what it is you're wanting to do?

btw...might want to be carefull there mixing the string commands and list commands...using lrange on a string is asking for trouble if there are any odd chars like {}"() in there. in any event, lrange of a list from 0 to end is just the same list...without knowing the syntax of the numeric tho, not sure what you're looking for *chuckle*

roland
[/code]
O
Ofloo
Owner
Posts: 953
Joined: Tue May 13, 2003 1:37 am
Location: Belguim
Contact:

Post by Ofloo »

unreal hehe sorry if you want to use it on others use 311 unreal has hidden ips i gues when other ircd's have it .. oh yes also added fail safe now

i want only my bots ip
you won't get dnslookup to work
and it does work ;)

Code: Select all

bind EVNT - init-server conn:init 

proc conn:init init-server { 
  putserv "whois $botnick" 
}

bind RAW - 378 reslove:raw

proc reslove:raw {from key arg} {
global botnick
  set bothost [join [lrange $arg 0 end]]
  set sbothost [lindex [split $bothost @] 1]
  set nslookup [dnslookup $sbothost reslove:ipaddress]
}

proc reslove:ipaddress {ipaddres hostname status} {
  set wfile [open "MyIP" "w"]
  puts -nonewline $wfile $ipaddres
  close $wfile
  putlog "Succesfully cached ip: \002$ipaddres\002."
}

proc MyIP {} {
  set rfile [open "MyIP" "r"] 
  set MyIP [read $rfile]
  close $rfile 
  if {"$MyIP" == "" || "$MyIP" == "0.0.0.0"} {
    foreach a {a b c d e f g h i j k} { 
      catch { 
      set external [socket $a.root-servers.net 53] 
      set MyIP [lindex [fconfigure $external -sockname] 0] 
      close $external             
      } 
    if { ![string equal $MyIP ""] } { break } 
    }
    return $MyIP
  } else {
    return $MyIP
  }
}

bind pub - !test test:pub 

proc test:pub {nick uhost handle chan arg} {
  putserv "notice $nick :[MyIP]"
}
XplaiN but think of me as stupid
O
Ofloo
Owner
Posts: 953
Joined: Tue May 13, 2003 1:37 am
Location: Belguim
Contact:

Post by Ofloo »

btw...might want to be carefull there mixing the string commands and list commands...using lrange on a string is asking for trouble if there are any odd chars like {}"() in there. in any event, lrange of a list from 0 to end is just the same list...without knowing the syntax of the numeric tho, not sure what you're looking for *chuckle*
thats the main reason why i use lrange and not lindex .. ? or am i wrong again cause if i remember correctly same thing is been told to me in the passed or something like that and i they suggested to use lrange and not lindex ..

and yes i tested what you sad, well sort of change raw to ramdom raws and result always was ip 0.0.0.0 so thats why the fail safe its not a perfect one the script is more relayable but in case it fails ..
Last edited by Ofloo on Thu Aug 14, 2003 3:06 pm, edited 1 time in total.
XplaiN but think of me as stupid
O
Ofloo
Owner
Posts: 953
Joined: Tue May 13, 2003 1:37 am
Location: Belguim
Contact:

Post by Ofloo »

oh and sorry again for putting up a topic with no question didn't mean it like this .. :/ tnx for understanding ;)
XplaiN but think of me as stupid
r
rolandguy
Voice
Posts: 25
Joined: Wed Aug 13, 2003 1:50 pm

Post by rolandguy »

ahh, try the USERHOST <botnick> server command to get your bots IP...is the 302 numeric :)

not positive how unreal has things set up these days, so dunno if a user can see their own *real* host in their WHOIS reply...but either way, USERHOST always returns an IP for a client using the command on itself, for exactly that reason ;)

roland
r
rolandguy
Voice
Posts: 25
Joined: Wed Aug 13, 2003 1:50 pm

Post by rolandguy »

all TCL commands that start with the letter l are list commands, except "load" and possibly some module commands. basicly all lists are are just strings, but by calling it a list, it interprets {} and " as signalling the beginning and end of parts of the list. for example:

{ "something" "something else" }

in the literal sense, this is a string, because it is just ascii characters, 8 bits each. but taken in the context of a list...is much more usefull :).

using your old code:

Code: Select all

proc reslove:raw {from key arg} { 
  global botnick 
  set bothost [join [lrange $arg 0 end]] 
  set sbothost [lindex [split $bothost @] 1] 
  set nslookup [dnslookup $sbothost reslove:ipaddress] 
}
$arg is a string, and is treated as a single object. no matter what is contained in that string, TCL doesn't care, doesn't even look at it. but by using lrange (list range), the TCL interpreter forces the string into a list structure. so if (for example) you had: "{\/}y name is Bot" in the realname field of the whois reply, you bot would puke. it would try to interpret all of the special chars in that string as special chars...instead of just treating the whole thing as one object, and each char as just an anonymous 8 bits.
if you are wanting to use the string as a list, however, you need to [split $arg]. this escapes all the special characters in the original string, and adds new special characters to form a list.

"{\/}y name is Bot" -> { "\{\\/\}y" "name" "is" "Bot" }

in any case, even with a properly formated list, [lrange $list 0 end] does absolutely nothing ;) I'm thinking all you need for that proc is:

Code: Select all

proc reslove:raw {from key arg} { 
  set bothost [lindex [split $arg @] 1] 
  set nslookup [dnslookup $sbothost reslove:ipaddress] 
}
(of course, you could skip the bothost var all togeather, but wanted to make sure things are clear ;)

hope this helps :)

roland
User avatar
user
&nbsp;
Posts: 1452
Joined: Tue Mar 18, 2003 9:58 pm
Location: Norway

Post by user »

Ofloo wrote:

Code: Select all

...
  foreach a {a b c d e f g h i j k} { 
    catch { 
      set external [socket $a.root-servers.net 53] 
      set MyIP [lindex [fconfigure $external -sockname] 0] 
      close $external             
    } 
    if {![string equal $MyIP ""] } { break } 
  }
...
Why catch everything (only socket would cause an error) and not even use the return value? This is a rewrite that will gain the same result:

Code: Select all

foreach a {a b c d e f g h i j k} { 
  if {[catch {socket $a.root-servers.net 53} s]} continue
  set MyIP [lindex [fconfigure $s -sockname] 0] 
  close $s
  break
}
Also, you might wanna change the order of those root-servers (putting the ones close to you at the start of the list)
r
rolandguy
Voice
Posts: 25
Joined: Wed Aug 13, 2003 1:50 pm

Post by rolandguy »

sure is alot of wasted code for eggdrop TCL...if you're already connected to chat, and all you want is your own IP...

Code: Select all

bind EVNT - init-server conn:init 
bind RAW - 302 reslove:raw 

proc conn:init init-server {
  global botnick
  putserv "USERNAME $botnick" 
} 

proc reslove:raw {from key arg} {
  global bot_ip
  set bot_ip [lindex [split $arg @] 1]
  set wfile [open "MyIP" "w"] 
  puts -nonewline $wfile $bot_ip 
  close $wfile
  putlog "Succesfully cached ip: \002$bot_ip\002." 
}
that is, if you even want to bother writing it to a file. since the global variable $bot_ip is reset every time the bot connects, there's really not much reason to save it...unless you want to use the IP for an external program.

or am I still not getting what you mean? lol

roland
O
Ofloo
Owner
Posts: 953
Joined: Tue May 13, 2003 1:37 am
Location: Belguim
Contact:

Post by Ofloo »

Why catch everything (only socket would cause an error) and not even use the return value? This is a rewrite that will gain the same result:
changed it to your code and crash :/ ?

Code: Select all

foreach a {a b c d e f g h i j k} { 
  if {[catch {socket $a.root-servers.net 53} s]} continue 
  set MyIP [lindex [fconfigure $s -sockname] 0] 
  close $s 
  break 
} 


can't put my finger on it .. :/
ahh, try the USERHOST <botnick> server command to get your bots IP...is the 302 numeric
True that would be easyer good point ;) and would work all the time hehe
that is, if you even want to bother writing it to a file. since the global variable $bot_ip is reset every time the bot connects, there's really not much reason to save it...unless you want to use the IP for an external program.
[05:43]Tcl error [test:pub]: can't read "bot_ip": no such variable
and if it would work and the bot is binded to 192.168.0.1
XplaiN but think of me as stupid
r
rolandguy
Voice
Posts: 25
Joined: Wed Aug 13, 2003 1:50 pm

Post by rolandguy »

Ofloo wrote:
[05:43]Tcl error [test:pub]: can't read "bot_ip": no such variable
and if it would work and the bot is binded to 192.168.0.1
did you "global bot_ip" in test:pub?

roland
O
Ofloo
Owner
Posts: 953
Joined: Tue May 13, 2003 1:37 am
Location: Belguim
Contact:

Post by Ofloo »

yes i did global
XplaiN but think of me as stupid
r
rolandguy
Voice
Posts: 25
Joined: Wed Aug 13, 2003 1:50 pm

Post by rolandguy »

Code: Select all

proc test:pub {nick host hand chan args} { 
  global bot_ip
  putserv "notice $nick :$bot_ip" 
}
?

roland
Locked