As long as you master the principle, you can also write a so-called "hacker" program. The following I lead you to use VB to write a remote control program in person. So as to uncover its veil of mystery.
First, the control used
Use the Winsock control in your program. The Winsock control is an ActiveX control that uses the TCP protocol or the UDP
Discusses connecting to and exchanging data with a remote computer. As with the timer control, the Winsock control is not visible at run time. Winsock working principle is: The client sends the connection request to the server, the server side listens to the client's request continuously, when the two agreement communication, the client and the server side establishes the connection, then the client and the server side can realize bidirectional data transmission. In actual programming, one server-side application and one client application must be established, each with its own Winsock control in two applications. First, set the protocol used by the Winsock control, where we use the TCP protocol. Now, let's start with VB to create two programs, one is the client program MyClient, the other is the server-side program myserver.
Second, the preparation of client programs
First to build the client program myclient. Create a form in the MyClient program, load the Winsock control, called the TcpClient, use the TCP protocol, add two text boxes (Text1 and Text2), enter the server's IP address and port number, and then create a button (CD1), To establish a connection, you can initialize the connection after you press the following code:
private sub cd1_click()
tcpclient.romotehost=text1.text
tcpclient.romoteport=val(text2.text)'端口号,缺省为1001
tcpclient.connect '调用connect方法,与指定IP地址的计算机进行连接
cd1.enabled=false
end sub
After the connection is the question of how to handle the data received. When a connection is established between the client and the server, if any one end receives the new data, the DataArrival event of the Winsock control is triggered and, in response to the event, the data sent can be obtained using the GetData method. For example, you can write code in the TcpClient DataArrival event as follows:
private sub tcpclient_dataarrival(byval bytestotal as long)
dim x as string
tcpclient.getdata x '使用getdata获得发送来的数据
.......
End sub
The omission in the following section represents the specific processing of the received data, which the reader can write according to the actual situation.
Iii. writing server-side programs
First set up a form, load the Winsock control, the name is TCPServer. Also add a text box on the form Text1 to display the client's IP address and the data information sent by the client.
When the client program runs, after the client program presses the connection button, the client requests a connection to the server-side program, and the server-side Connectionrequest event is triggered, so the server-side program resolves the connection problem. You can use the Connectionrequest event to complete this feature. The code is as follows:
'在窗体的load事件中对tcpserver控件进行初始化
private sub form_load()
tcpserver.localport=1001
tcpserver.listen '把服务器置于监听检测状态
end sub
'服务器端接收到客户端的连接请求,首先检查当前状态是否处于连接关闭状态
Private sub tcpclient_connectionrequest(Byval requestID as long)
If tcpserver.state<>sckclosed then '检查控件的state属性是否为关闭
Tcpserver.close '
Tcpserver.accept requestID '
End if
End sub
Now we add the following code to the DataArrival event in the server-side program TCPServer so that the server-side program can receive instructions from the client side and run the appropriate program.
Testing Remote Control Program
Now you can run the two programs in two computers that use the TCP/IP protocol to connect to each other. On the client side you press the connection button, then enter "C:mmand.com", you can see the server side immediately open a DOS window, imagine if it runs some destructive command what will happen? This is one of the most basic remote control programs. Of course, the real hacker program is much more complicated, but the fundamentals are the same. Now it's time for you to come to an epiphany?