Vous êtes sur la page 1sur 4

International Journal of Latest Research in Science and Technology

Vol.1,Issue 4 :Page No.389-390 ,November-December (2012)


http://www.mnkjournals.com/ijlrst.htm

ISSN (Online):2278-5299

REMOTE SYSTEM CONTROLLER USING SOCKET


PROGRAMMING
Deepak Vashisth1, Ashish Kr Luhach2, Dr. Jitender Kumar3,
Department of Information Technology, Dronacharya College of Engineering, Gurgaon, India
( 2luhach@live.com.au)
Abstract : - Remote System Controller is a program that manages the server and allows us to monitor and control our server over a
network. It is a program that provides a system to supervise a geographically distributed or physically inaccessible systems .It's
server/remote platform is basically designed to run on a LINUX & UNIX interface & can also be used in WINDOWS with little
modification . Whereas it's controller/client program can be run from every network supporting device. Requires simple network between
the two machines (remote & controller) . As it is designed in C language , provides wide use & no limitation of access on remote. Here I
have taken controller as another system supporting C language but this controller can be designed for any device like Smart Phones ,
Tablets , Netbook and the list never ends.
Keywords Sockets, System Calls,Pipes;

INTRODUCTION
The Berkeley forms of UNIX introduced the socket interface as a
new model of communication, which extends the concept of a pipe.
Hence LINUX also incorporated socket interface[1] . Socket can be
used in the same way as pipes, but they include communication
across a network of computers. A program on one machine can use
sockets to communicate with a process on another, which allows for
client/server systems that are scattered across a network[1]. Sockets
may also be used to handle processes on the same machine. Also,
the sockets interface has been made available for Windows via a
publicly available specification called WinSock[1]. Windows socket
services are delivered by a Winsock.dll system file. Thus, Windows
programs can communicate across a network to Linux and UNIX
computers and vice versa providing client/server systems. Although
the encoding interface for WinSock isnt quite the same as UNIX
sockets.[1]

A. SOCKETS & THEIR BASICS


IEEE and ISO started standardization of network. IEEE
standardized protocols for the Token Ring and Ethernet network
types, while ISO established a networking model known as Open
Systems Interconnect (OSI) reference model. In OSI model the
communication between two geographically distinct networks are
broken in various logical levels. OSI a theoretical model established
for the institutions to conceptualize the working of its network. In
session layer of OSI model sockets are established and maintained
for communication between two systems. Practically Socket work
on network layer and uses IP protocol. For transmission of data it
uses TCP and UDP protocols. Sockets are conceptual and can't be
used to access lower or higher layers of network. That is it don't
know whether it is being user on Ethernet ,dialup or any other
network topology. Sockets even don't care which higher level
protocol (HTTP, FTP, STP) is using it[3]. It basically distributes data
into various small packets and sends and secure its transmission
throughout the network.
B.UNIX Socket Programming

In the client server architecture maintained by UNIX, a system


referred as a client makes a request to connect to another system
referred as server for allowing access to some services. The services
that runs at server actually runs on ports (like certain ports are fixed
for application layer port 21 for FTP, 23 for Telnet,80 for HTTP) so
the client showed know the IP address of the system and the port of
the services. In case of server these information about the client are
not necessary. Client serves as an active device as it takes the first
move to establish the connection by sending a request , this request
or the first package contains all the information about its address
which are then used by server for further response. Here server acts
as a passive device which waits for clients request. [3]
C.

System Calls:

When we talk about the core of Operating System , the kernel is a


collection of low-level interface that controls hardware of the
system, these are called device driver. These device drivers are
access through a group of predefined functions called System calls.
System calls provide direct interface between hardware of the
system for their usabilities through softwares[1].
Here in this paper we will talk about a specific system call ie.
Sockets. All the functions of socket interface is mentioned in the
header file socket.h. This provides us with all the functionalities
for establishment of sockets between two system within a network .
D.

Concept Of Pipes:

To connect one process with another we attach, or pipe ,the output


of one process to the input of another. Easiest way to pass the output
of one process to the input of another is popen() and pclose()
functions.[1]
Popen passes the output of the command and assign it a file
pointer , which can then be further pass to another process.
FILE *popen(const char *command, const char *open_mode);
After process associated with popen is finished we can close the
file stream with the pclose command. It returns an integer.
int pclose(FILE *stream_to_close);

Client Server Architecture:

ISSN: 2278-5299

389

Deepak Vashisthet.al, International Journal of Latest Research in Science and Technology.

USUAL COMMUNICATION THROUGH SOCKETS


Usually sockets are used as a mode to transfer
data/message from Machine A to Machine B. For this the
only necessity is both the machines should be connected
through a network. As socket is a software concept so it
doesn't matter on which type of hardware network it is being
used .
In this mode of communication through sockets a simple program
is run on either of the machine having its counterpart on the other
machine .When a socket is created in Machine A then its counterpart
is also created in Machine B . Then through socket functions both
the sockets are interconnected and are made ready to communicate.

Fig.2: Remote System Controller .


ALGORITHEMS
A.REMOTE MACHINE PROGRAM
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>

Fig1:Usual Socket Communication

#include <sys/socket.h>
#include <netinet/in.h>

The figure here includes a framework of socket and uses


following features:
A. Initialization of processes
MACHINE B creates a new socket and waits for connection. When
the client program at MACHINE B is executed then it is
successfully connected to the server at MACHINE B.

#include <arpa/inet.h>

int main(int argc, char **argv){


..
char BUFFER[400];

B. Sending data through sockets:


The Client then reads the data entered by various processes and
passes it bit-by-bit to the socket. Which channelize the data to the
server.

FILE *fp;

C. Receiving the Data & giving the response:


The data/message passed through the socket is the received by
the server, then read and the response is given to the client .

. .. . . . .

IN REMOTE SYSTEM CONTROL:

../* Here we are waiting for recieving command from remote


machine */

We will extend this simple transferring of data/message to transfer


UNIX & LINUX commands. Here we will run a "remote.c " program
in our server that creates socket and waits for the "controller.c" to
pass the commands .These commands are then passed to the function
that executes the command and creates a pipe to its output which is
then send to the client. Hence the client can execute any command on
the server terminal.

ISSN: 2278-5299

host_socket = socket(AF_INET, SOCK_DGRAM, 0);

z
=
bind(host_socket,
sizeof(host_add));

(struct

sockaddr

*)&host_add,

R = recvfrom(host_sock, datagram, 512, 0, (struct sockaddr


*)&remote_add, &remote_len);
buffer[R] = 0;
.........
/* opening a stream by executing the command */

390

Deepak Vashisthet.al, International Journal of Latest Research in Science and Technology.

fp = popen(BURRER, "r");

struct sockaddr_in host_add;

........

struct sockaddr_in remote_add;

remote_socket = socket(AF_INET, SOCK_DGRAM, 0);

.......

/* collecting the output n sending to the remote */

host_socket = socket(AF_INET,SOCK_DGRAM, 0);

while(fgets(BUFFER, sizeof(BUFFER)-1, fp) != NULL){

......

l = sendto(remote_socket,BUFFER, strlen(BUFFER), 0, (struct


sockaddr *)&remote_add, sizeof(remote_add));

r
=
bind(host_socket,
sizeof(host_add));

..........

/*reads the command & passes through socket */

(struct

sockaddr

*)&host_add,

fgets(B,400, stdin);
remote_socket = socket(AF_INET, SOCK_DGRAM, 0);
/* Here the command is sent to remote machine through UDP */
r = sendto(remote_socket,B, strlen(B),
*)&remote_add, sizeof(remote_add));

0,

(struct

sockaddr

/* Here the output of the command is collected from the remote */


........
l = recvfrom(host_sock, datagram, 400, 0, (struct sockaddr
*)&remote_add, &remote_len);
B[l] = 0;
Fig2: Screenshot Of Remote System Initially.

printf("%s", B);
. . . . . . . . . . . .. . .

Fig3: Screenshot Of Remote System After Execution of ls


Command
In this program you can easily see that the whole working of remote
system controller is based on remotely execution of commands This
is achieved by the use of popen() function present in header file
<stdio.h>
which create a pipe between the program that calls it and the
executed command. It returns a pointer to an open stream which
can be used for either reading or writingto the pipe.[5]

B.CONTROLLER PROGRAM:
#include <stdio.h>
. .. .. . . . .. .

Fig.4: Initial Screenshot of Controller .

Hence the controller is allowed to enter the command it wants to


pass to the the remote / server. The command is passed through
sockets . Then at remote these commands are passed in the pipe
function popen which then execute the command and assign a file
stream to it . This file stream is then passed back to the controller .
Then content of file stream or the output of the command can be
seen on the controller screen.

int main(int argc, char **argv){


......
char B[400];

ISSN: 2278-5299

391

Deepak Vashisthet.al, International Journal of Latest Research in Science and Technology.

accessories with your system. With simple modification it can be


used as intrusion software for mobiles , tablets and pc's.

REFERENCES
1.

Neil
Matthew,
Richard
Stones
Programming,Third Edition Pg.587

,Beginning

Linux

2.

Programming Linux sockets, Part 2 , Presented by ibm/ developer


Works.

3.

Computer Networks (CS425), Instructor: Dr. Dheeraj Sanghi

4.

The Open Group Base Specifications Issue 6


IEEE Std 1003.1, 2004 Edition
Copyright 2001-2004 The IEEE and The Open Group, All Rights
reserved.

5.

Ming Xue &Changjun Zhu ,The Socket Programming and Software


Design for Communication Based on Client/Server

APPLICATIONS OF RSC
Now a days every network is using Sockets as their base for
packet transfer from one machine to the other so with the use of
RSC you can control your System from any device (it could be
another system , a mobile or your touch pads ). It can change the
way of using the network.
1. For Smart Phones:
A simple smart phone supporting JAVA, ANDROID, iOS and
BLACKBERRY can utilize concept of sockets to transfer
commands to the remote device where the program is running. Only
some commands of controller needed to be modified on the bases of
the platform .
2. For Tablets:
Tablets like iPad ,Samsung Galaxy, Touch Pad, Akash , etc can also
pass the command to control their associate remote system . As
Android is a successor of Java so it also supports sockets , hence can
be designed to pass UNIX or LINUX commands.

CONCLUSION
With the expansion and wide use of LINUX & UNIX base OS,
RSC concept can ease the remote monitoring system. It provides
you with limitless access to your remote system and gives you a
handy resource/device to use a complicated machine. It provides
you controls to supervise and maintain your system from any part of
the world. This simple code along with java socket program can be
used as a full remote desktop controller. As android also uses
LINUX shells so this can be used to control android mobiles

ISSN: 2278-5299

392

Vous aimerez peut-être aussi