mIRC Home    About    Download    Register    News    Help

Print Thread
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!

Joined: Aug 2005
Posts: 1,052
L
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* }
Joined: Jun 2006
Posts: 508
D
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)
}


Joined: Aug 2005
Posts: 1,052
L
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* }
Joined: Jun 2006
Posts: 508
D
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.

Joined: Dec 2002
Posts: 503
B
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.

Joined: Jun 2006
Posts: 508
D
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

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

Joined: Aug 2005
Posts: 1,052
L
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* }

Link Copied to Clipboard