反向通信-在ip中捕获数据 [英] Reverse communication -Capturing data in ip

查看:76
本文介绍了反向通信-在ip中捕获数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我需要使用IP地址连接客户端服务器,并需要捕获数据.我能够连接服务器,但无法捕获数据.我该怎么办.

谁能帮我解决这个问题.

在此先感谢,
Jai

Hi,

I need to connect client server using IP address and need to capture the data. I am able to connect the server but i am not able to capture the data. How could i do this.

Could any one help me to sort out this issue.

Thanks in Advance,
Jai

推荐答案

错误是您尚未在Connect_to_Server中为接收器分配任何网络流.仅分配作家.由于没有为Receiver分配任何内容,因此它将不会引用任何网络流.将您的接收器指向从Connected TcpClient获得的网络流.
The error is that you haven''t assigned any network stream to the Receiver in the Connect_to_Server. Only Writer is assigned. Since Receiver is not assigned anything it will not be referencing any network stream. Point your receiver to the network stream you got from the Connected TcpClient.


乔希,

感谢您的快速回复.下面是代码.

我尝试捕获数据对象引用未设置为实例"时出错



使用系统;
使用System.Collections.Generic;
使用System.Net.Sockets;
使用System.Text;
使用System.IO;
使用Microsoft.Win32;
使用System.Reflection;
使用System.Runtime.InteropServices;

命名空间客户端
{
课程计划
{
公共静态布尔IsConnected;
公共静态NetworkStream接收器;

公共静态NetworkStream Writer;

静态void Main(string [] args)
{

Connect_to_Server();
Read_Command();

}

公共静态无效Connect_to_Server()
{

TcpClient连接器=新的TcpClient();

GetConnection:

Console.WriteLine(输入服务器IP:");

字符串IP = Console.ReadLine();

试试

{
Connector.Connect(IP,2000);

IsConnected = true;

作家= Connector.GetStream();

}

赶上

{

Console.WriteLine(连接到目标服务器时出错!请按任意键重试.");

Console.ReadKey();

Console.Clear();

goto GetConnection;

}

//让用户知道他们已连接,并且如果他们输入HELP,他们将获得要使用的命令列表.
Console.WriteLine(连接已成功建立到" + IP +.");
}

公共静态无效Read_Command()
{
而(true)
{
试试
{
byte [] RecPacket =新的byte [1000];

Receiver.Read(RecPacket,0,RecPacket.Length);

Receiver.Flush();

字符串命令= Encoding.ASCII.GetString(RecPacket);

string [] CommandArray = System.Text.RegularExp< B></B> ressions.Regex.Split(Command,"@");

Command = CommandArray [0];

开关(命令)
{


案例"MESSAGE":


字符串Msg = CommandArray [1];

System.Windows.Forms.MessageBox.Show(Msg.Trim(''\ 0''));

休息;

案例"OPENSITE":

字符串Site = CommandArray [1];

System.Diagnostics.Process IE =新的System.Diagnostics.Process();

IE.StartInfo.FileName ="iexplore.exe";

IE.StartInfo.Arguments = Site.Trim(''\ 0'');

IE.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Maximized;

IE.Start();

休息;
}

}
赶上
{

休息;
}

}
}

}}
Hi Jos

Thanks for quick reply. Below is the code.

Error while i am trying to capture the data "Object reference not set to an instance"



using System;
using System.Collections.Generic;
using System.Net.Sockets;
using System.Text;
using System.IO;
using Microsoft.Win32;
using System.Reflection;
using System.Runtime.InteropServices;

namespace Client
{
class Program
{
public static bool IsConnected;
public static NetworkStream Receiver;

public static NetworkStream Writer;

static void Main(string[] args)
{

Connect_to_Server();
Read_Command();

}

public static void Connect_to_Server()
{

TcpClient Connector = new TcpClient();

GetConnection:

Console.WriteLine("Enter server IP :");

string IP = Console.ReadLine();

try

{
Connector.Connect(IP, 2000);

IsConnected = true;

Writer = Connector.GetStream();

}

catch

{

Console.WriteLine("Error connecting to target server! Press any key to try again.");

Console.ReadKey();

Console.Clear();

goto GetConnection;

}

//Let user know they connected and that if they type HELP they''ll get a list of commands to use.
Console.WriteLine("Connection successfully established to " + IP + ".");
}

public static void Read_Command()
{
while (true)
{
try
{
byte[] RecPacket = new byte[1000];

Receiver.Read(RecPacket, 0, RecPacket.Length);

Receiver.Flush();

string Command = Encoding.ASCII.GetString(RecPacket);

string[] CommandArray = System.Text.RegularExp<B></B>ressions.Regex.Split(Command, "@");

Command = CommandArray[0];

switch (Command)
{


case "MESSAGE":


string Msg = CommandArray[1];

System.Windows.Forms.MessageBox.Show(Msg.Trim(''\0''));

break;

case "OPENSITE":

string Site = CommandArray[1];

System.Diagnostics.Process IE = new System.Diagnostics.Process();

IE.StartInfo.FileName = "iexplore.exe";

IE.StartInfo.Arguments = Site.Trim(''\0'');

IE.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Maximized;

IE.Start();

break;
}

}
catch
{

break;
}

}
}

}}


这篇关于反向通信-在ip中捕获数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆