retrieve IP of local machine

Login or Register for Dates, Times and to Reply

Thread Tools Search this Thread
# 1  
retrieve IP of local machine

Hi all,

I am writing a program to retrieve the IP address or machine name of the local machine using C.
Is there any C function that does this?

ny clue will be of gr8 help!!!

thanx a lot.
# 2  
try this,

# include<netdb.h>
# include<stdio.h>
# include<netinet/in.h>
# include<arpa/inet.h>
# include<sys/socket.h>

int main(int argc, char *argv[])
long conv;
struct hostent *h;
if(argc != 2)
fprintf(stderr, "USAGE: <binary> <IP_ADDRESS>\n");
if( (int) (conv=inet_addr(argv[1])) == -1 )
fprintf(stderr, "IP Notation Wrong\n");
h=gethostbyaddr((char*)&conv, sizeof(conv), AF_INET);
if(h == (struct hostent *) NULL)
fprintf(stderr, "Resolve failed for %s\n", argv[1]);
fprintf(stderr, "Name: %s\n", h->h_name);
return 0;

Login or Register for Dates, Times and to Reply

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Computers #499
Difficulty: Medium
The term 'self-documenting' code means the compiler has advanced A.I. which documents what each line of code actually does.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Help with fetching the data from remote machine from my jumpbox(local machine)

Team, Presently i am running a script from my local box(i.e jumpbox) to all the remote machines.Basically fetching basic queries like pwd,mkdir,touch etc and i am able to successfully fetch it from my local machine.But when i want to check certain database related queries like the dbstat... (20 Replies)
Discussion started by: whizkidash
20 Replies

2. Red Hat

iptables applied in local machine, can't ssh remote machine after chain changed to DROP

I want to SSH to Server from my machine, my ip was Source Destination was UP, with IP This is LAN Network there are 30 Machine's Connected to the network and working fine, I'm Playing around the local machine's because I need to apply the same rules in... (2 Replies)
Discussion started by: babinlonston
2 Replies

3. Shell Programming and Scripting

To run a local shell script in a remote machine by passing arguments to the local shell script

I need to run a local shell script on a remote machine. I am able to achieve that by executing the command > ssh -qtt user@host < However, when I try to pass arguments to it fails. Any pointers would be appreciated. (7 Replies)
Discussion started by: Sree10
7 Replies

4. UNIX for Advanced & Expert Users

FTP While transfering files to local machine to remote machine

Hi Am using unix Ksh Am getting the problem while transferring zero size files through the script . When i transfer zero size files from local machine to remote machine manually i can able to do it . My question its beause of zero size files am not able to transfer through script ? or its... (2 Replies)
Discussion started by: Venkatesh1
2 Replies

5. UNIX for Dummies Questions & Answers

Retrieve data from Remote machine

Hello Please I ask if it is possible to recover data that is stored on a remote machine that I access via ssh on a usb ? if so, how? Thank you so much (5 Replies)
Discussion started by: chercheur857
5 Replies

6. Shell Programming and Scripting

How to transfer files from unix machine to local machine using shell script?

Hi All.. Am new to Unix!! Am creating a shell script in which a scenario is like i have transfer the output file from unix machine (Server) to local directory (Windows xp). And also i have to transfer the input file from the local directory to Unix machine (Server) Any help from you... (1 Reply)
Discussion started by: vidhyaS
1 Replies

7. Shell Programming and Scripting

Retrieve all DNS zones (domains) from local server

Hello, I am trying to retrieve all DNS zones from the local bind server without parsing the /var/named folder, removing .db from the zone file names and the special zones files. I am looking for some kind of named, dig etc command that would retrieve all domains from the server eventually with... (2 Replies)
Discussion started by: AndyB78
2 Replies

8. Red Hat

To find the LATEST file from a dir on REMOTE machine and SCP to local machine?

Hi All, URGENT - Please help me form a scipt for this: I need the LATEST file from a dir on REMOTE machine to be SCP'd to a dir on local machine. (and I need to execute this from local server) I know that the below cmd is used to find the LATEST file from a dir. But this command is not... (3 Replies)
Discussion started by: me_ub
3 Replies

9. IP Networking

Workgroup of local machine

Hi Guys, How to find the Workgroup/Domain name of my local machine in unix? Please suggest some link. Thanks. sunil. (3 Replies)
Discussion started by: skumar2011
3 Replies

10. IP Networking

how to retrieve IP address of a machine

hi is there is any command that retrieves the IP address of a machine. Also is there any function in c that does the same. thankx (5 Replies)
Discussion started by: mridula
5 Replies

Featured Tech Videos