mIRC Home    About    Download    Register    News    Help

Topic Options
#188840 - 31/10/07 01:26 PM Sock Snippet to return Public IP
Horstl Offline
Hoopy frood

Registered: 03/11/06
Posts: 1559
Loc: Germany
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!

Top
#188843 - 31/10/07 02:24 PM Re: Sock Snippet to return Public IP [Re: Horstl]
Lpfix5 Offline
Hoopy frood

Registered: 10/08/05
Posts: 1052
Loc: Canada
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* }

Top
#188862 - 31/10/07 08:02 PM Re: Sock Snippet to return Public IP [Re: Horstl]
deegee Offline
Fjord artisan

Registered: 16/06/06
Posts: 508
Loc: Storage
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)
}


Top
#188864 - 31/10/07 08:11 PM Re: Sock Snippet to return Public IP [Re: deegee]
Lpfix5 Offline
Hoopy frood

Registered: 10/08/05
Posts: 1052
Loc: Canada
Does Bvar ignore html tags all togheter?
_________________________
Code:
if $reality > $fiction { set %sanity Sane }
Else { echo -a *voices* }

Top
#188867 - 31/10/07 08:17 PM Re: Sock Snippet to return Public IP [Re: Lpfix5]
deegee Offline
Fjord artisan

Registered: 16/06/06
Posts: 508
Loc: Storage
The recieved data from that page is not html, just the headers and the IP.

Top
#188869 - 31/10/07 08:50 PM Re: Sock Snippet to return Public IP [Re: deegee]
Bekar Offline
Fjord artisan

Registered: 11/12/02
Posts: 503
Loc: Melbourne, Australia
After you've done a /localinfo -u, $ip should be your public IP address.

Top
#188870 - 31/10/07 08:54 PM Re: Sock Snippet to return Public IP [Re: Bekar]
deegee Offline
Fjord artisan

Registered: 16/06/06
Posts: 508
Loc: Storage
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

Top
#188872 - 31/10/07 10:08 PM Re: Sock Snippet to return Public IP [Re: deegee]
Horstl Offline
Hoopy frood

Registered: 03/11/06
Posts: 1559
Loc: Germany
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

Top
#188885 - 31/10/07 11:36 PM Re: Sock Snippet to return Public IP [Re: Horstl]
Lpfix5 Offline
Hoopy frood

Registered: 10/08/05
Posts: 1052
Loc: Canada
grin blush
_________________________
Code:
if $reality > $fiction { set %sanity Sane }
Else { echo -a *voices* }

Top