dongpiao1983 2011-08-15 13:07
浏览 102
已采纳

如何从本地Web浏览器连接到远程telnet服务器并发送预定义命令?

I have a call center application running using php/javascript. When the operator is in his mac or windows or linux with web browser such as Firefox/Chrome/Opera/Internet explorer. I need to make a real time connection to a remote server for sending a command like "make call".

But how can i do using javascript a telnet connection to remote server? Is this possible with javascript if so how and which browsers?

Thanks

Note: without using this

1) http://matthaynes.net/blog/2008/07/17/socketbridge-flash-javascript-socket-bridge/

2) http://stephengware.com/proj/javasocketbridge/

Follow up: Only i capture this packets while using Chrome? (Firefox/Opera/Midori/Safari, none worked).

# tcpdump -n -x -X -i any port 23
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on any, link-type LINUX_SLL (Linux cooked), capture size 65535 bytes

16:37:00.446070 IP 1.164.45.143.56295 > 1.164.45.143.telnet: Flags [S], seq 205310205, win 32792, options [mss 16396,sackOK,TS val 37248521 ecr 0,nop,wscale 6], length 0
    0x0000:  4500 003c 96f4 4000 4006 a561 51a4 2d8f  E..<..@.@..aQ.-.
    0x0010:  51a4 2d8f dbe7 0017 0c3c c8fd 0000 0000  Q.-......<......
    0x0020:  a002 8018 fe94 0000 0204 400c 0402 080a  ..........@.....
    0x0030:  0238 5e09 0000 0000 0103 0306            .8^.........
16:37:00.446109 IP 1.164.45.143.telnet > 1.164.45.143.56295: Flags [R.], seq 0, ack 205310206, win 0, length 0
    0x0000:  4500 0028 0000 4000 4006 3c6a 51a4 2d8f  E..(..@.@.<jQ.-.
    0x0010:  51a4 2d8f 0017 dbe7 0000 0000 0c3c c8fe  Q.-..........<..
    0x0020:  5014 0000 0031 0000                      P....1..
16:37:00.446555 IP 1.164.45.143.56296 > 1.164.45.143.telnet: Flags [S], seq 196642802, win 32792, options [mss 16396,sackOK,TS val 37248521 ecr 0,nop,wscale 6], length 0
    0x0000:  4500 003c d9fb 4000 4006 625a 51a4 2d8f  E..<..@.@.bZQ.-.
    0x0010:  51a4 2d8f dbe8 0017 0bb8 87f2 0000 0000  Q.-.............
    0x0020:  a002 8018 fe94 0000 0204 400c 0402 080a  ..........@.....
    0x0030:  0238 5e09 0000 0000 0103 0306            .8^.........
16:37:00.446581 IP 1.164.45.143.telnet > 1.164.45.143.56296: Flags [R.], seq 0, ack 196642803, win 0, length 0
    0x0000:  4500 0028 0000 4000 4006 3c6a 51a4 2d8f  E..(..@.@.<jQ.-.
    0x0010:  51a4 2d8f 0017 dbe8 0000 0000 0bb8 87f3  Q.-.............
    0x0020:  5014 0000 41bf 0000                      P...A...
  • 写回答

1条回答 默认 最新

  • dream543211 2011-08-15 13:26
    关注

    Best you can do with javascript is an AJAX request using the XMLHttpRequest. If your telnet server can handle a bunch of garbage commands before it gets to the good one then you'll have no problem. The AJAX request can connect to the telnet server and send plain text commands using the POST mechanism. The telnet server will receive the HTTP header first which it will ignore with "invalid command" errors before it gets to your valid telnet commands in the POST body.

    var xtel = new XMLHttpRequest();
    // replace 123.123.123.123 with the correct IP address
    xtel.open("POST", "http://123.123.123.123:23", true);
    // you won't be able to get a proper response from the telnet server 
    xtel.onreadystatechange = function () {return true;} 
    xtel.send("valid command 1" + "
    " + "valid command 2" + "
    ");
    

    This would be akin to ...

    <> telnet 123.123.123.123 23
    <> GET / HTTP/1.1
    <> ACCEPT: */*
    <> HOST: 123.123.123.123
    <>
    <> valid command 1
    <> valid command 2
    

    However, the above is a kludge and your best bet would be to use PHPs sockets http://php.net/manual/en/function.stream-socket-client.php to perform the connect and send the command(s).

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 数学的三元一次方程求解
  • ¥20 iqoo11 如何下载安装工程模式
  • ¥15 本题的答案是不是有问题
  • ¥15 关于#r语言#的问题:(svydesign)为什么在一个大的数据集中抽取了一个小数据集
  • ¥15 C++使用Gunplot
  • ¥15 这个电路是如何实现路灯控制器的,原理是什么,怎么求解灯亮起后熄灭的时间如图?
  • ¥15 matlab数字图像处理频率域滤波
  • ¥15 在abaqus做了二维正交切削模型,给刀具添加了超声振动条件后输出切削力为什么比普通切削增大这么多
  • ¥15 ELGamal和paillier计算效率谁快?
  • ¥15 蓝桥杯单片机第十三届第一场,整点继电器吸合,5s后断开出现了问题