Server obtaining client's IP Address. How?

Server obtaining client's IP Address. How?

Post by Donald C. Ason » Tue, 30 Jan 1996 04:00:00



Hi all,

I need to find ipaddress or address of a connected client.  I
have look in the sockaddr structure when the accept function
is called, but it was not complete.  I am thinking of calling
getpeername(..). Is there a place I can look this up? (ftp
sites, etc.) or maybe someone here has a piece of code that
will do this.

Any suggestions would be appreciated.  
Thanks,
Donald.
--
                           ***   ***   ***
                           * *   * *   * *
                           * * * * *   * *
                           * * * * *   * *
                           * *   * *   * *
                           ***   ***   ***

                    "SOME HEADS ARE GONNA ROLL"
                 "HELL-BENT HELL-BENT FOR LEATHER"

 
 
 

Server obtaining client's IP Address. How?

Post by Jonathan Len » Wed, 31 Jan 1996 04:00:00



> Hi all,

> I need to find ipaddress or address of a connected client.  I
> have look in the sockaddr structure when the accept function
> is called, but it was not complete.  I am thinking of calling
> getpeername(..). Is there a place I can look this up? (ftp
> sites, etc.) or maybe someone here has a piece of code that
> will do this.

> Any suggestions would be appreciated.
> Thanks,
> Donald.
> --
>                            ***   ***   ***
>                            * *   * *   * *
>                            * * * * *   * *
>                            * * * * *   * *
>                            * *   * *   * *
>                            ***   ***   ***

>                     "SOME HEADS ARE GONNA ROLL"
>                  "HELL-BENT HELL-BENT FOR LEATHER"

As long as the client is logged in, you can parse the /etc/utmp
 or /etc/utmpx (Solaris) file for things like hostname, userid,
etc. The library routine that does this is getutent() or
getxutent() (Solaris) and should be available on a man page.

Two potential problems:

If a user rexecs something, then there will not be an entrym for
the client in the utmp file.

If the client is in DNS, getutent() may return the resolved hostname
instead of the full IP address. May be a problem, may not be.

Respectfully,

Jonathan Lent
JCPenney Company (comments are mine -- of course)

 
 
 

Server obtaining client's IP Address. How?

Post by geie » Thu, 01 Feb 1996 04:00:00



> > Hi all,

> > I need to find ipaddress or address of a connected client.  I
> > have look in the sockaddr structure when the accept function
> > is called, but it was not complete.  I am thinking of calling
> > getpeername(..). Is there a place I can look this up? (ftp
> > sites, etc.) or maybe someone here has a piece of code that
> > will do this.

Perhaps that will help (any comments appreciated!!!)

// --- newClientConnection
// ---
// --- create a seperate socket for a new client connection
// ---
// --- in : socket of server
// --- out: socket-descriptor for the connection-endpoint to
// ---      the new client

static int newClientConnection(int server_socket) {
    struct sockaddr_in sockaddr;
    int                client_socket;
    int                addr_len;
    char*              client_name;

    addr_len = sizeof(sockaddr);
    client_socket = accept(server_socket, (struct sockaddr *)&sockaddr,
                           &addr_len);
    // ---
    // --- get hostname of requesting client
    // ---
    struct hostent *hp  =
      gethostbyaddr( (char*) &sockaddr.sin_addr,
                     sizeof( struct in_addr),
                     sockaddr.sin_family);
    if ( hp )
        // --- real hostname
        client_name = hp->h_name;
    else
        // --- internet-address
        client_name = inet_ntoa( sockaddr.sin_addr );

    cout << "ConReq by client " << client_name
         << " [" << inet_ntoa( sockaddr.sin_addr ) << "]" << endl;

    return client_socket;

Quote:}

--- Roland.

---
Roland Geier                    Phone: ++49 (851) 509-3107          
Universitaet Passau, GER        Fax  : ++49 (851) 509-1802

D-94032 Passau

 
 
 

1. Obtain IP address of client's machine in called Perl script

Hi all,

I am using Perl on Linux and I have a situation where I would like to
provide access to a site thus

www.mydom.mysite.com.auThe index.html in the root auto loads a login
script and I would like the login script to check against a list of
privileged IP addresses and for those it offers slightly different
options.I have been reading in the Perl Apache Module and there is
mention of a function

get_remote_host() that says

"Lookup the client's DNS hostname. If the configuration directive
HostNameLookups is set to off, this returns the dotted decimal
representation of the client's IP address instead. Might return undef if
the hostname is not known. "

I am not sure this is quite what I want. As even for the list of
privileged users (IP addresses) they will not have a DNS name, it will
just be a list of fixed IP addresses on the network.

Further it seems that the Apache module is a bit of over kill to obtain
just this little bit of information.

Does anyone know the way I should really do this

Any help much appreciated

Thanks

Derek

2. Apache and PHP

3. Obtaining a Telnet Client's IP Address

4. Hardware failure status.

5. Obtaining a Telnet client's IP address

6. Font comparison screenshots

7. How to Obtain clients IP address from Perl Scrip called from browser

8. ANN: 'twander' 2.34 Released For FreeBSD et al

9. Obtaining IP Address from Hardware Address

10. Using DHCP to obtain PC's IP address from Solaris box

11. obtain IP address from a mac address

12. obtaining IP address from DHCP server

13. Windows 2000 clients can't obtain gateway from Linux server