mIRC Homepage
Posted By: Horstl Sock Snippet to return Public IP - 31/10/07 01:26 PM
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!
Posted By: Lpfix5 Re: Sock Snippet to return Public IP - 31/10/07 02:24 PM
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.
Posted By: deegee Re: Sock Snippet to return Public IP - 31/10/07 08:02 PM
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)
}

Posted By: Lpfix5 Re: Sock Snippet to return Public IP - 31/10/07 08:11 PM
Does Bvar ignore html tags all togheter?
Posted By: deegee Re: Sock Snippet to return Public IP - 31/10/07 08:17 PM
The recieved data from that page is not html, just the headers and the IP.
Posted By: Bekar Re: Sock Snippet to return Public IP - 31/10/07 08:50 PM
After you've done a /localinfo -u, $ip should be your public IP address.
Posted By: deegee Re: Sock Snippet to return Public IP - 31/10/07 08:54 PM
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
Posted By: Horstl Re: Sock Snippet to return Public IP - 31/10/07 10:08 PM
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
Posted By: Lpfix5 Re: Sock Snippet to return Public IP - 31/10/07 11:36 PM
grin blush
© mIRC Discussion Forums