TightVNC를 이용한 reverse connection

amchiryo의 이미지

안녕하세요.

이 내용은
http://bbs.kldp.org/viewtopic.php?t=28261&highlight=vnc
에 aero님이 쓰신 것을 이용해 리눅스 용으로 바꾼 것입니다.
aero님에게 감사드립니다.

저의 경우 회사내에서 사설IP를 이용하는 컴퓨터에
리눅스를 깔고 제 자료를 모두 넣는 서버로 사용중입니다.
그런데 문제가 하나 있었습니다.
즉, 집에 있을 때, 제 자료를 접근하고 싶어도
접근이 안되는 것입니다.
당연히 안되는 것이지요...
네트웍 외부에서 사설IP로 된 내부
네트웍을 접속할 수는 없으니까요...

이 문제를 해결하기 위해 고민, 고민을 하다가
aero 님의 팁을 보았으나...
윈도우용이라는 것이 문제였습니다.
리눅스용으로 바꿀 수 없는지 comment를 달았지만
답변을 얻지는 못하였습니다.

그래서 제가 허접하게 PHP를 이용하여 아래와 같이
짜서 사용중(2시간째)인데, 아직은 문제가 없습니다.

필요한 것: vnc.txt 파일을 올리고 읽을 수 있는 홈페이지 계정
사용법: php -a vnc.php

* 반드시 앞에 링크한 aero님의 팁을 먼저 보셔야 이해가 될 겁니다.
* 개선된 것이 있으면 팁 또는 comment로 올려 주세요...
감사합니다.

==vnc.php : 아래부터 copy 해서 파일을 만드세요. ===============================

<?php



set_time_limit(0);
// there is no time limit in this program execution

function ReturnEntireArray($array,$root)
{ $result = '';
  foreach (array_keys($array) as $element)
  {
   $my_array=$array[$element];
   if(is_array($my_array))
   {
     ShowEntireArray($my_array,$root . "[" . $element . "]");
   }
   else
   {
     $result .= $root . "[" . $element . "]=" . $array[$element];
   }
  }
 return $result;
}

function GetURL($url_file)
{$fh = fopen($url_file, 'r');    // use 'r' so file can be read

if ($fh)
{
  $url = fread($fh, 20);
  $url = trim($url);
  fclose($fh);
} else  echo "Could not open URL file '$url_file'";

#echo "URL is '$url'";
return $url;
}


function GetNetstat()
{$str=exec("/bin/netstat -an", $array);
$netstat_result = ReturnEntireArray($array, '');
#echo $netstat_result;
return $netstat_result;
}


########################################################################
# definition of basic parameters
########################################################################

$url_file = 'http://your domain/vnc.txt';
$interval = 30;
// 30 seconds interval before reacquisition of URL from $url_file



########################################################################
# Main
# 1) acquisition of URL and reverse connection to the acquired URL
#   within perpetual loop of 30 seconds interval
# 2) if the reverse connection is not made, there should be
#   an attempt to connect with the aquired URL
########################################################################

while(1){
$url = GetURL($url_file);
$netstat = GetNetstat();
#echo $url;
#echo $netstat;
if (!preg_match("/$url:5500/", $netstat))  {
   $vnc=system("vncconnect -display your_display ".$url.":5500");
   }




sleep ($interval);
// waits for $interval seconds
}



?>
Forums: 
amchiryo의 이미지

위 소스에서
your domain,
your display
라고 된 부분만 바꾸시면
바로 사용이 가능합니다.

sephiron의 이미지

#!/bin/sh
URL="여기에 웹주소를 써 넣으세요"
DISPLAY="Xvnc display" # ex. host:1
while true
do
        IP=""
        IP=`wget -q -O - $URL`
        if [ "$IP" ]
        then
                vncconfig -display "$DISPLAY" -connect $IP
                while true
                do
                STATUS=`netstat -t | awk '{ print $5 }' | grep ":5500"`
                [ "$STATUS" ] || break
                sleep 30
                done
        fi
        sleep 30
done

vncserver 등을 사용하여 Xvnc 데몬이 동작중이어야 합니다.

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.