i_my
Replies to this thread:

More by i_my
What people are reading
Subscribers
:: Subscribe
Back to: Kurakani General Refresh page to view new replies
 how to write code in C to read client IP (browser) address
[VIEWED 5905 TIMES]
SAVE! for ease of future access.
Posted on 12-01-08 10:31 PM     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

need help with the C code.
designing a proxy server.
can't find a function that would return client IP address.
help please.

 
Posted on 12-01-08 10:53 PM     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

let me google that for you
http://unixwiz.net/tools/whoamip.html
is this what you had in mind?

some codes here:
http://forums.debian.net/viewtopic.php?t=31673&sid=77365c8c16168343211ec674e17826cc




 
Posted on 12-01-08 11:38 PM     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

Thanks Sedif. :-)

 
Posted on 12-01-08 11:50 PM     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

wow sedif..didnt know abt let me google that for you, that was nice

http://tinyurl.com/6p2z7d (This just for test)

Dont know much abt C, but got following from http://www.cygwin.com/ml/cygwin/2004-04/msg00894.html, might be of some help.

/* little utility to get the IP address of the machine

- prints the IP address in triple-dotted form xxx.yyy.zzz.www,

or nothing if can't get it.

- this code is a fragment from EpidEm code.

*/

#include <stdio.h>

#include <arpa/inet.h>

#include <netinet/in.h>

#include <unistd.h>

#include <netdb.h>

/*

Returns the IP address of this host.

- if host have more than 1 IP, only 1 (the first) is returned.

- return is in network byte order

- thanks to Doct. Ghini (www.cs.unibo.it/~ghini)

return: 0 if unsuccessful, the IP otherwise

*/

in_addr_t get_my_IP()

{

/* have you ever seen a hostname longer than a screen (80cols)?*/

char name[80]; /*store my hostname*/

struct hostent * hostent_ptr;

int ret;

ret = gethostname (name, 80);

if(ret == -1) {

/*printf ("ERROR gethostname() failed, Errno=%d \nDescription: %s\n", errno,

strerror(errno));*/

return 0;

}


hostent_ptr = gethostbyname(name);


if(hostent_ptr == NULL)

{

/*printf ("ERROR gethostbyname() failed, h_errno=%d \nDescription: %s\n",
h_errno, hstrerror(h_errno));*/

return 0;

}

/*h_addr_list contains IPs of this host in network byte order */

return ((struct in_addr *)hostent_ptr->h_addr_list[0])->s_addr; /*get the
first IP.*/

}

int main()

{

in_addr_t my_ip = get_my_IP();

if (my_ip != 0)

{

struct in_addr temp;

temp.s_addr = my_ip;

printf("%s\n", inet_ntoa(temp));

}

return 0;

}


 
Posted on 12-02-08 12:28 AM     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

np
@techGuy: ya read a Digg post on it, cleaver idea.

 
Posted on 12-02-08 7:49 AM     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

Yes , gethostbyname( ) does it.

But werent you looking for Client's IP Address? And if you are coding for a Proxy Server, and all you can do is code in that server? I'd suggest you use connection request headers from the clients to find its IP Address.

 
Posted on 12-02-08 7:46 PM     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

Can someone know how to crack these array problems please.

 1. Write a program to double the array elements with odd indices?

Eg. Element 1, 2,3,4,5,6,7,8

Soln: 1,6,10,14 <program only double the element with odd indices>

 

2. Find the first element larger than 100.

 

    

thank you


 
Posted on 12-03-08 1:56 AM     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 
 


Please Log in! to be able to reply! If you don't have a login, please register here.

YOU CAN ALSO



IN ORDER TO POST!




Within last 60 days
Recommended Popular Threads Controvertial Threads
TPS Re-registration case still pending ..
Toilet paper or water?
ढ्याउ गर्दा दसैँको खसी गनाउच
Tourist Visa - Seeking Suggestions and Guidance
I hope all the fake Nepali refugee get deported
and it begins - on Day 1 Trump will begin operations to deport millions of undocumented immigrants
From Trump “I will revoke TPS, and deport them back to their country.”
Travel Document for TPS (approved)
wanna be ruled by stupid or an Idiot ?
To Sajha admin
Those who are in TPS, what’s your backup plan?
MAGA denaturalization proposal!!
How to Retrieve a Copy of Domestic Violence Complaint???
advanced parole
MAGA and all how do you feel about Trumps cabinet pick?
All the Qatar ailines from Nepal canceled to USA
MAGA मार्का कुरा पढेर दिमाग नखपाउनुस !
NOTE: The opinions here represent the opinions of the individual posters, and not of Sajha.com. It is not possible for sajha.com to monitor all the postings, since sajha.com merely seeks to provide a cyber location for discussing ideas and concerns related to Nepal and the Nepalis. Please send an email to admin@sajha.com using a valid email address if you want any posting to be considered for deletion. Your request will be handled on a one to one basis. Sajha.com is a service please don't abuse it. - Thanks.

Sajha.com Privacy Policy

Like us in Facebook!

↑ Back to Top
free counters