jojo's blog--快樂憂傷都與你同在
          為夢想而來,為自由而生。 性情若水,風(fēng)起水興,風(fēng)息水止,故時而激蕩,時又清平……
          posts - 11,  comments - 30,  trackbacks - 0
          Here is the script in it's
          entirety.
          It would be taylored to only execute one
          command not an open perl script. Better
          than having root .rhosts everywhere.
          I think where it does the:

          print F $Line;

          at the bottom is where I could put some
          kind of execute statement.
          Take the string and run it not print it
          to a file.



          socket.client.perl
          #!/usr/bin/perl
          #===============================================
          # Client -- using object interface
          # Support Windows and UNIX
          #===============================================
          use IO::Socket;
          my $sock = new IO::Socket::INET (
          PeerAddr => '128.166.11.13',
          PeerPort => '9999',
          Proto => 'tcp',
          );
          die "Could not create socket: $!"n" unless $sock;
          print $sock "Hi there!"n";
          $sock->send("Hi again!"n");

          close($sock);


          socket.server.perl
          #!/usr/bin/perl
          #===============================================
          # Server -- using object interface
          # Support Windows and UNIX
          #===============================================

          #use Proc::Daemon;
          use IO::Socket;
          #Proc::Daemon::Init();

          use POSIX qw(setsid);

          sub daemonize {
          die "Can't fork" unless defined (my $child = fork());
          exit 0 if $child;
          setsid();
          open(STDIN, "</dev/null");
          open(STDOUT, ">/dev/null");
          open(STDERR, ">&STDOUT");
          chdir '/';
          umask(0);
          #$ENV{PATH} = '/bin:/sbin:/usr/bin:/usr/sbin';
          return $$;
          };

          &daemonize;
          while() {
          my $new_sock = $sock->accept();

          ####################################
          # Put a message to file. #
          ####################################

          while(defined($Line = <$new_sock>)) {
          open (F,"+>>/lhome/root/testfile.txt");
          print F $Line;
          close F;
          };
          close($sock);
          }; #End of while cycle
          A. Clay Stephenson Expert in this area This member has accumulated 80000 or more points     
          May 21, 2004 16:47:45 GMT  10 pts     
          In that case, $Line has your input so you can use it to execute whatever you like.

          Typically, your client should send a formatted request string of some type. I like to use <tabs> to separate the fields and then your server responds each time it sees a new line of input.



          ------------------------------------------------------------------------------------------------------

          All I am saying in that any client/server architecture, you must establish some sort of protocol.

          Let's suppose that your server does 4 things:
          1) lists files in a dedicated directories
          2) removes 1 file
          3) add's a line to an existing file
          4) kill the server

          Your create client requests that adhere to this, for example, you formant your protocol like this
          request_code<tab>string1<tab>string2<LF>

          Now every line sent to the server expects these 3 arguments -- although some may simply be dummy args. Tabs are nice because unlike spaces or colons or commas they are not typically part of strings. Typically the request_code is something very easy to parse; e.g 1 - list; 2 - remove, 4 - kill,kill,kill

          If you wanrt to see some examples of this along with a little explanation, go to www.sysadminmag.com and look under the April '03 issue. I wrote an article that used Perl a Perl client/server pair to implement multi-host semaphores. Their web page also has a source code link where you will find the client and server pieces.

          -----------------------------------------------------------------------------------------------

          For now though. I just wanted something
          simple to get around the root .rhosts problem. I was thinking as a security measure
          of passing a code to the server.pl but don't
          know the perl syntax at this time.
          Could you show me the simple syntax for
          passing two args.

          e.g.

          From client.pl send:

          1234 shutdown.sh

          On server.pl check code then run command:

          1234 shutdown.sh


          On my client.perl I currently have:

          print $sock "shutdown.sh"

          On my server.perl I have:

          while(defined($Line = <$new_sock>)) {
          system($Line);
          close($sock);
          }; #End

          posted on 2009-08-06 12:11 Blog of JoJo 閱讀(294) 評論(0)  編輯  收藏 所屬分類: 每日一記 、My Script

          <2025年6月>
          25262728293031
          1234567
          891011121314
          15161718192021
          22232425262728
          293012345

          常用鏈接

          留言簿(6)

          隨筆檔案

          文章分類

          文章檔案

          新聞分類

          新聞檔案

          相冊

          收藏夾

          搜索

          •  

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 观塘区| 招远市| 北宁市| 泾源县| 淳化县| 龙南县| 尼玛县| 普陀区| 洛浦县| 化州市| 寿阳县| 鹤壁市| 芦山县| 榆中县| 温泉县| 建平县| 安庆市| 赣州市| 伊川县| 临沭县| 黄梅县| 盘锦市| 溧阳市| 灵石县| 华亭县| 赞皇县| 红桥区| 镇巴县| 措美县| 巴东县| 和龙市| 四子王旗| 怀安县| 普安县| 沂水县| 茂名市| 涿鹿县| 富阳市| 舟曲县| 武夷山市| 府谷县|