Sponsored Content
Full Discussion: Proxy server/client in Perl
Top Forums Shell Programming and Scripting Proxy server/client in Perl Post 302241292 by Dabheeruz on Monday 29th of September 2008 03:50:05 AM
Old 09-29-2008
Proxy server/client in Perl

I have been toying with a Proxy client/server app that will listen on the CLIENT system on lets say port 7070. User's browser proxy setting is configured for "localhost" port "7070".
When this proxy app gets a request for a URL it should FETCH the URL and display it on the browser.

I already made the listener portion of the script (it was easy) but how can I then call and get the URL that the user will request on their browser and display it to the browser acting like a proxy.

Here is the code so far. I am totally stuck Smilie ..any help is highly appreciated Smilie

Code:
#!/usr/bin/perl
use IO::Socket;

my $sock= new IO::Socket::INET (
                                LocalHost=> 'localhost',
                                LocalPort=> '7070',
                                Proto=> 'tcp',
                                Listen=> 1,
                                Reuse=> 1,
                                Type=> SOCK_STREAM,
                                );
die "Could not create socket:  $!\n" unless $sock;

my $new_sock = $sock->accept();
        while (<$new_sock>) {
                print $_;
        }
        close ($sock);

 

10 More Discussions You Might Find Interesting

1. IP Networking

routing through a proxy server

I'm new to this forum, so please be gentle ! I need to get my IBM RS running AIX4.3 onto the internet to a particular ftp server, through a NT server running proxy services. This NT server is directly connected to our internet router vis a secondary NIC on the NT server. When I add the route... (2 Replies)
Discussion started by: garry
2 Replies

2. UNIX for Dummies Questions & Answers

unix server behind MS proxy server

I'm trying to get a Unix server on the internet (mostly for DNS requests) but this server is on a network behind a Proxy server. How can I configure my unix server that he will pass the proxy server for internet requests? (2 Replies)
Discussion started by: RSlegers
2 Replies

3. Shell Programming and Scripting

(perl) Microsoft SQL Server client for solaris. cant find it...

let me save everyone the pain that it caused me. This is all free. And make sure it is in this order 1) make sure you have the latest version of perl installed 2) make sure you have NET:aemon installed 3) make sure you have RPC::PlServer & PlClient (the bundle has both) 4) make sure... (3 Replies)
Discussion started by: Optimus_P
3 Replies

4. Linux

how to get IP for proxy server

i have installed a proxy server on my linux box . how to get the IP for that proxy . cheers (3 Replies)
Discussion started by: ppass
3 Replies

5. IP Networking

Software/tool to route an IP packet to proxy server and capture the Proxy reply as an

Hi, I am involved in a project on Debian. One of my requirement is to route an IP packet in my application to a proxy server and receive the reply from the proxy server as an IP packet. My application handles data at the IP frame level. My application creates an IP packet(with all the necessary... (0 Replies)
Discussion started by: Rajesh_BK
0 Replies

6. Programming

Client/Server Socket Application - Preventing Client from quitting on server crash

Problem - Linux Client/Server Socket Application: Preventing Client from quitting on server crash Hi, I am writing a Linux socket Server and Client using TCP protocol on Ubuntu 9.04 x64. I am having problem trying to implement a scenario where the client should keep running even when the... (2 Replies)
Discussion started by: varun.nagpaal
2 Replies

7. Solaris

Connessione con client SFTP via Proxy

Ciao a tutti, ho l'esigenza di collegarmi in SFTP (client Winscp) ad una macchina solaris che vedo attraverso un'altra macchina solaris. Come configuro la connessione ? Sulla macchina diretta non ho problemi mentre sulla remota non so come configurare i parametri per utilizzare la diretta come... (1 Reply)
Discussion started by: bobbyred
1 Replies

8. Programming

Sending and Receiving data between Client, HTTP Proxy, and Remote Server

I am having problems receiving data from a remote server. It seems that I can send an HTTP request to any host such as http://www.google.com, but I can't get a reply. I'm sending the host a HTTP 1.0 request that is formatted as such: GET / HTTP/1.0 Host: http://www.google.com Connection:... (0 Replies)
Discussion started by: shubham92
0 Replies

9. Shell Programming and Scripting

proxy server using perl

I want to write a perl script on a server to behave like a proxy server. I want to be able to enter the hostname and port on firefox proxy settings (or IE, chrome, whatever) and then go to a site, and have my webserver forward the request to another server, and forward the response back to the... (2 Replies)
Discussion started by: Arun_Linux
2 Replies

10. UNIX for Dummies Questions & Answers

enable all operations to use a proxy server , redhat server

Hi, i would like to enable all operations/connections to use a proxy server in a redhat server , witch file should i config to get this for all conections .... Thanks (0 Replies)
Discussion started by: prpkrk
0 Replies
IO::Socket::INET(3pm)					 Perl Programmers Reference Guide				     IO::Socket::INET(3pm)

NAME
IO::Socket::INET - Object interface for AF_INET domain sockets SYNOPSIS
use IO::Socket::INET; DESCRIPTION
"IO::Socket::INET" provides an object interface to creating and using sockets in the AF_INET domain. It is built upon the IO::Socket interface and inherits all the methods defined by IO::Socket. CONSTRUCTOR
new ( [ARGS] ) Creates an "IO::Socket::INET" object, which is a reference to a newly created symbol (see the "Symbol" package). "new" optionally takes arguments, these arguments are in key-value pairs. In addition to the key-value pairs accepted by IO::Socket, "IO::Socket::INET" provides. PeerAddr Remote host address <hostname>[:<port>] PeerHost Synonym for PeerAddr PeerPort Remote port or service <service>[(<no>)] | <no> LocalAddr Local host bind address hostname[:port] LocalHost Synonym for LocalAddr LocalPort Local host bind port <service>[(<no>)] | <no> Proto Protocol name (or number) "tcp" | "udp" | ... Type Socket type SOCK_STREAM | SOCK_DGRAM | ... Listen Queue size for listen ReuseAddr Set SO_REUSEADDR before binding Reuse Set SO_REUSEADDR before binding (deprecated, prefer ReuseAddr) ReusePort Set SO_REUSEPORT before binding Broadcast Set SO_BROADCAST before binding Timeout Timeout value for various operations MultiHomed Try all addresses for multi-homed hosts Blocking Determine if connection will be blocking mode If "Listen" is defined then a listen socket is created, else if the socket type, which is derived from the protocol, is SOCK_STREAM then connect() is called. Although it is not illegal, the use of "MultiHomed" on a socket which is in non-blocking mode is of little use. This is because the first connect will never fail with a timeout as the connect call will not block. The "PeerAddr" can be a hostname or the IP-address on the "xx.xx.xx.xx" form. The "PeerPort" can be a number or a symbolic service name. The service name might be followed by a number in parenthesis which is used if the service is not known by the system. The "PeerPort" specification can also be embedded in the "PeerAddr" by preceding it with a ":". If "Proto" is not given and you specify a symbolic "PeerPort" port, then the constructor will try to derive "Proto" from the service name. As a last resort "Proto" "tcp" is assumed. The "Type" parameter will be deduced from "Proto" if not specified. If the constructor is only passed a single argument, it is assumed to be a "PeerAddr" specification. If "Blocking" is set to 0, the connection will be in nonblocking mode. If not specified it defaults to 1 (blocking mode). Examples: $sock = IO::Socket::INET->new(PeerAddr => 'www.perl.org', PeerPort => 'http(80)', Proto => 'tcp'); $sock = IO::Socket::INET->new(PeerAddr => 'localhost:smtp(25)'); $sock = IO::Socket::INET->new(Listen => 5, LocalAddr => 'localhost', LocalPort => 9000, Proto => 'tcp'); $sock = IO::Socket::INET->new('127.0.0.1:25'); $sock = IO::Socket::INET->new( PeerPort => 9999, PeerAddr => inet_ntoa(INADDR_BROADCAST), Proto => udp, LocalAddr => 'localhost', Broadcast => 1 ) or die "Can't bind : $@ "; NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE As of VERSION 1.18 all IO::Socket objects have autoflush turned on by default. This was not the case with earlier releases. NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE METHODS sockaddr () Return the address part of the sockaddr structure for the socket sockport () Return the port number that the socket is using on the local host sockhost () Return the address part of the sockaddr structure for the socket in a text form xx.xx.xx.xx peeraddr () Return the address part of the sockaddr structure for the socket on the peer host peerport () Return the port number for the socket on the peer host. peerhost () Return the address part of the sockaddr structure for the socket on the peer host in a text form xx.xx.xx.xx SEE ALSO
Socket, IO::Socket AUTHOR
Graham Barr. Currently maintained by the Perl Porters. Please report all bugs to <perlbug@perl.org>. COPYRIGHT
Copyright (c) 1996-8 Graham Barr <gbarr@pobox.com>. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. perl v5.16.2 2012-10-11 IO::Socket::INET(3pm)
All times are GMT -4. The time now is 09:49 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy