Click here to Skip to main content
15,868,292 members
Articles / Programming Languages / C#

Internet Magic (Proxy Server) Windows Application

Rate me:
Please Sign up or sign in to vote.
3.00/5 (8 votes)
10 Apr 2010CPOL3 min read 68.3K   8.8K   38   18
Windows application which creates a proxy server to share Internet over any TCP/IP network

Project code

Class architecture

1.jpg

Introduction

In any network, each system has a unique IP address which identifies the system in the network. This application aims at distributing the internet over a network, based on the IP address. Administrator registers the IP addresses of the client in the application (proxy server), which then allows access to the various services provided by the server on the systems identified by these IP addresses.

This project is being developed using C# .NET in Visual Studio 2005.

Feature Set

  • IP address based internet sharing
  • Network monitoring to monitor online client activity
  • Web filter which can be used to block specified web sites
  • Time scheduling to limit client’s on-line time
  • Bandwidth usage statistics to monitor the bandwidth
  • Account authentication for Socks protocol
  • Socks support allows various internet messengers and FTP downloaders
  • Portmap maps a port on a specific IP address to another port on another IP address
  • This application also supports HTTP/FTP

Background

In computer networks, a proxy server is a server (a computer system or an application program) that services the requests of its clients by forwarding requests to other servers. A client connects to the proxy server, requesting some service, such as a file, connection, web page, or other resource, available from a different server. The proxy server provides the resource by connecting to the specified server and requesting the service on behalf of the client. A proxy server may optionally alter the client's request or the server's response, and sometimes it may serve the request without contacting the specified server. In this case, it would 'cache' the first request to the remote server, so it could save the information for later, and make everything as fast as possible. A proxy server that passes all requests and replies unmodified is usually called a gateway or sometimes tunnelling proxy. A proxy server can be placed in the user's local computer or at various points between the user and the destination servers or the Internet.

Using the Code

This application created using VS2005 code can directly open in Visual Studio using its Solution file.

The language used is C# using .NET 2.0, executable file will be created on program execution.

C#
//SAMPLE OF THE CODE
int Ret;
try  {
    Ret = ClientSocket.EndReceive(ar);
} catch {
    Ret = -1;
}
if (Ret <= 0) { //Connection is dead :(
    Dispose();
    return;
}
HttpQuery += Encoding.ASCII.GetString(Buffer, 0, Ret);
/******************For Authentication************************/
HeaderFields = ParseQuery(HttpQuery);
if (HeaderFields == null || !HeaderFields.ContainsKey("Host"))
{
    SendBadRequest();
    return;
}
int Port;
string Host;

if (HttpRequestType.ToUpper().Equals("CONNECT"))
{ //HTTPS
    Ret = RequestedPath.IndexOf(":");
    if (Ret >= 0)
    {
        Host = RequestedPath.Substring(0, Ret);
        if (RequestedPath.Length > Ret + 1)
            Port = int.Parse(RequestedPath.Substring(Ret + 1));
        else
            Port = 443;
    }
    else
    {
        Host = RequestedPath;
        Port = 443;
    }
}
else
{ //Normal HTTP
    Ret = ((string)HeaderFields["Host"]).IndexOf(":");
    if (Ret > 0)
    {
        Host = ((string)HeaderFields["Host"]).Substring(0, Ret);
        Port = int.Parse(((string)HeaderFields["Host"]).Substring(Ret + 1));
    }
    else
    {
        Host = (string)HeaderFields["Host"];
        Port = 80;
    }
    if (HttpRequestType.ToUpper().Equals("POST"))
    {
        int index = HttpQuery.IndexOf("\r\n\r\n");
        m_HttpPost = HttpQuery.Substring(index + 4);
    }
}
string dir = Environment.CurrentDirectory;
if (!dir.Substring(dir.Length - 1, 1).Equals(@"\"))
    dir += @"\";
Program prx = Program.obj;

//

Points of Interest

The product is a very low cost system with a Windows application, where a system in which application is installed has a purpose to provide web services over the connected network. The administrator controlling this server has to give details of the client about their authorization to access these services and until when they can access it. The system then automatically generates a request window on client requesting access to the services which, if registered by administrator of server, then client can fully utilize the services provided by serve. Then system automatically controls the access time and monitors the client for their activity in the internet. After the validity period of the client has expired, then the client will be automatically barred from accessing these services.

History

  • 10th April, 2010: Initial post

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
India India
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralMy vote of 1 Pin
MChris200611-May-11 8:43
MChris200611-May-11 8:43 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.