mIRC Home    About    Download    Register    News    Help

Print Thread
Sock Snippet to return Public IP #188840 31/10/07 01:26 PM
Joined: Nov 2006
Posts: 1,559
H
Horstl Offline OP
Hoopy frood
OP Offline
Hoopy frood
H
Joined: Nov 2006
Posts: 1,559
Hi there,
being absolutely green with socket stuff I need your help:
I'm looking for an socket snippet (or the like) to return ones current public IP address (I guess a page like www.ipaddressworld.com can return that information; maybe you have a smarter idea... com would be welcome, too... smile )

Thx in advance!

Re: Sock Snippet to return Public IP [Re: Horstl] #188843 31/10/07 02:24 PM
Joined: Aug 2005
Posts: 1,052
L
Lpfix5 Offline
Hoopy frood
Offline
Hoopy frood
L
Joined: Aug 2005
Posts: 1,052
why not return $ip?

if you must insist on getting an IP via sock then...

Code:
alias pip { sockopen pip whatismyipaddress.com 80 }

on 1:sockopen:pip:{
  .sockwrite -n pip GET / HTTP/1.1
  .sockwrite -n pip HOST: whatismyipaddress.com
  .sockwrite -n pip $crlf
}

on 1:sockread:pip:{
  if ($sockerr > 0) return 
  var %x | sockread -fn %x
  if (LOOKUPADDRESS isin %x) { %F = Current Public $+(IP:,[,$gettok($regsubex(%x,/([aA-zZ]|["<>=])/g,),1,32),]) }
  if (IP ADDRESS LOCATION isin %x) { echo -a %F $remove(%x,<TR><TD,colspan=3>,</td>,$chr(9)) }
}


Is sufficient. I added IP ADDRESS Location for you can remove the simply if statement if not needed.


Code:
if $reality > $fiction { set %sanity Sane }
Else { echo -a *voices* }
Re: Sock Snippet to return Public IP [Re: Horstl] #188862 31/10/07 08:02 PM
Joined: Jun 2006
Posts: 508
D
deegee Offline
Fjord artisan
Offline
Fjord artisan
D
Joined: Jun 2006
Posts: 508
This is probably a better site to use.
Code:
alias myip { sockopen myip www.whatismyip.com 80 }

on *:sockopen:myip:{
  if $sockerr { echo -a * Sockerr (myip): $sock(myip).wsmsg | return }
  sockwrite myip GET $+(/automation/n09230945.asp HTTP/1.0,$lf,HOST: whatismyip.com,$str($lf,2))
}
on *:sockread:myip:{
  sockread -f &a
  echo -a * My IP: $gettok($bvar(&a,1-).text,-1,10)
}


Re: Sock Snippet to return Public IP [Re: deegee] #188864 31/10/07 08:11 PM
Joined: Aug 2005
Posts: 1,052
L
Lpfix5 Offline
Hoopy frood
Offline
Hoopy frood
L
Joined: Aug 2005
Posts: 1,052
Does Bvar ignore html tags all togheter?


Code:
if $reality > $fiction { set %sanity Sane }
Else { echo -a *voices* }
Re: Sock Snippet to return Public IP [Re: Lpfix5] #188867 31/10/07 08:17 PM
Joined: Jun 2006
Posts: 508
D
deegee Offline
Fjord artisan
Offline
Fjord artisan
D
Joined: Jun 2006
Posts: 508
The recieved data from that page is not html, just the headers and the IP.

Re: Sock Snippet to return Public IP [Re: deegee] #188869 31/10/07 08:50 PM
Joined: Dec 2002
Posts: 503
B
Bekar Offline
Fjord artisan
Offline
Fjord artisan
B
Joined: Dec 2002
Posts: 503
After you've done a /localinfo -u, $ip should be your public IP address.

Re: Sock Snippet to return Public IP [Re: Bekar] #188870 31/10/07 08:54 PM
Joined: Jun 2006
Posts: 508
D
deegee Offline
Fjord artisan
Offline
Fjord artisan
D
Joined: Jun 2006
Posts: 508
Very true, however OP asked for "an socket snippet (or the like) to return ones current public IP address"

It may be that its for use when not connected to a server wink

Re: Sock Snippet to return Public IP [Re: deegee] #188872 31/10/07 10:08 PM
Joined: Nov 2006
Posts: 1,559
H
Horstl Offline OP
Hoopy frood
OP Offline
Hoopy frood
H
Joined: Nov 2006
Posts: 1,559
Thx to all of you!

Friends of mine had problems while using some bouncer: /localinfo -u resolved the bnc's IP... Due to your help, the /localinfo can now be set on connect to their "true" external IP.

Regards smile

Re: Sock Snippet to return Public IP [Re: Horstl] #188885 31/10/07 11:36 PM
Joined: Aug 2005
Posts: 1,052
L
Lpfix5 Offline
Hoopy frood
Offline
Hoopy frood
L
Joined: Aug 2005
Posts: 1,052
grin blush


Code:
if $reality > $fiction { set %sanity Sane }
Else { echo -a *voices* }