mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Feb 2003
Posts: 14
F
Pikka bird
OP Offline
Pikka bird
F
Joined: Feb 2003
Posts: 14
I need to tunnel a website from the internet to another local network (no I cant run NAT and so forth). But the problem with a tunnel is that it will send the wrong HOST option. So since the middle computer is running mirc I thought I would contruct a sort of a tunnel script for mirc.

It needs to accept connections on a port and when an connection i received open another connection to the website, then it should just tell the other one what the other one said. So for instance, the socklisten conneciton says "GET /", it should then send "GET /" to the website connection... Here is how my script looks like.


on 1:sockread:expressen:{
if ($sockerr > 0) goto end
:nextread
sockread %temphttp
if ($sockbr == 0) goto end
if (%temphttp == $null) %temphttp = -
sockwrite -n amino2 %temphttp
goto nextread
:end
}
alias httpredirect {
sockopen expressen xhtml.expressen.se 80
socklisten amino 90
}
on 1:socklisten:amino: {
sockaccept amino2
}
on 1:sockread:amino2:{
if ($sockerr > 0) goto end
:nextread
sockread %temphttp2
if ($sockbr == 0) goto end
if (%temphttp2 == $null) %temphttp2 = -
if (172.155.155.10:90 isin %temphttp2) { sockwrite -n expressen Host: xhtml.expressen.se }
else sockwrite -n expressen %temphttp2
goto nextread
:end
}

Now, when I do a /httpredirect and then try to access http://172.155.155.10:90 I get various errors. I have changed something to mess up the script completly, since now I get a lot of /sockwrite: line too long (line 7, script2.mrc) and /sockwrite: 'amino2' queue would exceed 16384 bytes (line 7, script2.mrc).. Yesterday it would send the first page (index.htm) but it would add some weird charectors here and there (I dont mind this since they dont have tags they wont be displayed anyway) but after it was received the web browser would still be expecting more, so I am thinking that it is expecting a terminate command or simular?

What do I need to do to get this to worK?

Joined: Apr 2003
Posts: 701
K
Hoopy frood
Offline
Hoopy frood
K
Joined: Apr 2003
Posts: 701
There are 2 lines like this:
if (%temphttp == $null) %temphttp = -
And that's very nice if you're going to display it, but a webserver and a web browser have no idea what a single - on a line means. You have to convert those back to a blank line: /sockwrite socket $crlf

For the rest, it might work, or it might not. I can also tell you I'm no fan of using goto for this.

Joined: Dec 2002
Posts: 1,245
M
Hoopy frood
Offline
Hoopy frood
M
Joined: Dec 2002
Posts: 1,245
Quote:

I can also tell you I'm no fan of using goto for this.

How would you (genericly) set up a sockread

Joined: Feb 2003
Posts: 14
F
Pikka bird
OP Offline
Pikka bird
F
Joined: Feb 2003
Posts: 14
Ok I have now made some changes to the script. It now looks like this,

on 1:sockread:expressen:{
if ($sockerr > 0) goto end
:nextread
sockread %temphttp
if ($sockbr == 0) goto end
if (%temphttp == $null) { goto nextread }
if (%temphttp == 0) && (%httpwrite == 1) { goto end }
if (%temphttp == 62e) { set %httpwrite 1 }
if ($len(%temphttp) < 4) { goto nextread }
if (%httpwrite == 1) && (%temphttp != 62e) { sockwrite -n amino $+ %socketname %temphttp }
goto nextread
:end
}
alias httpredirect {
set %socketname 1
write -c temp.xhtml $null
set %httpwrite 0
sockopen expressen xhtml.expressen.se 80
socklisten amino 90
}
on 1:socklisten:amino*: {
set %socketname $calc(%socketname + 1)
sockaccept amino $+ %socketname
}
on 1:sockread:amino*:{
if ($sockerr > 0) return
:nextread
sockread %temphttp2
if ($sockbr == 0) return
if (172.155.155.10:90 isin %temphttp2) { sockwrite -n expressen Host: xhtml.expressen.se }
else sockwrite -n expressen %temphttp2
goto nextread
:end
}


It will now correctly grab and send the index file, however after that it stops. I am guessing that the webbrowser is waiting for the pictures to be sent. I also figured out that the garbadge code which are three letters or numbers accure each time before a picture is placed that is local (/picture.jpg instead of www.domain.com/picture.jpg). Can someone help me get this script to work so it also sends pictures? If you want to try the script you only have to change 172.155.155.10 to localhost and then open localhost:90 in a browser... Also even though the source code of the index file is grabbed it wont be displayed until I do a /sockclose, I havent managed to find the correct place to put it.


Thanks

Joined: Apr 2003
Posts: 701
K
Hoopy frood
Offline
Hoopy frood
K
Joined: Apr 2003
Posts: 701
Code:
on *:SOCKREAD:socketname:{
  if ($sockerr) return
  var %data
  sockread %data
  while ((!$sockerr) &amp;&amp; ($sockbr)) {
    ; ... echo -s read $v1 bytes: %data
    if (%data == stophere) return
    if (sometimes isin %data) {
      ; ...
    }
    sockread %data
  }
}

IMHO about the only not-so-bad use of goto would be a 'SELECT' or 'CASE' statement until it's included in mIRC. Using combinations of if and while is usually more understandable for yourself or other coders reading your script.


Link Copied to Clipboard