The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > High Level Programming
Google UNIX.COM


High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Help Required: Command to find IP address and command executed of a user loggedout Security 2 08-06-2008 05:12 PM
sendmail "root... User address required." error csgonan SUN Solaris 10 04-03-2008 06:57 AM
replace <Address> with a var input by user r2007 Shell Programming and Scripting 4 06-16-2005 09:14 AM
network address and broadcast address? pnxi UNIX for Dummies Questions & Answers 7 11-10-2003 08:29 PM
Locate a user by their IP address jagannatha UNIX for Dummies Questions & Answers 7 05-22-2003 01:28 PM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1  
Old 11-21-2006
Registered User
 

Join Date: Nov 2006
Posts: 17
Get user name from ip address

hi all
i am new in unix programming i want some help from this forum, i want to know how to get user name of other machine in local network from its ip address or suggest any books for networking programming on unix

sachin
Reply With Quote
Forum Sponsor
  #2  
Old 11-21-2006
blowtorch's Avatar
Supporter
 
Join Date: Dec 2004
Location: Singapore
Posts: 2,326
User name? Or do you mean hostname? The usernames on a system usually won't have anything to to with the IP address of that system.
Reply With Quote
  #3  
Old 11-21-2006
Registered User
 

Join Date: Nov 2006
Posts: 17
host name

thank for this quick reply

so please tell about how to get host name from ip address, if you have any idea about web link or book about this problem please forward me
Reply With Quote
  #4  
Old 11-21-2006
blowtorch's Avatar
Supporter
 
Join Date: Dec 2004
Location: Singapore
Posts: 2,326
There are a few ways.
Not using C: Use actual unix commands instead of C library functions. Two of the methods are using grep on the /etc/hosts file, and using nslookup/dig. In a C program, you can use these via popen and fread/fgets/fscanf on the file pointer returned by popen.
Using C: Take a look at the man page of gethostbyname/gethostbyaddr.
Reply With Quote
  #5  
Old 11-21-2006
Registered User
 

Join Date: Oct 2003
Posts: 69
http://www.amazon.com/Unix-Network-P...e=UTF8&s=books

Unix Network Programming, Vol. 1: The Sockets Networking API, Third Edition.
ISBN: 0131411551

This book is absolutely priceless when learning anything about network comm. in Unix.
Reply With Quote
  #6  
Old 11-21-2006
Registered User
 

Join Date: Nov 2006
Location: Austria/Vienna
Posts: 232
another way if you are not using dns or /etc/hosts is:
ssh <ip> "hostname" but you'll need a userpasswort on the machine

or telnet or rlogin or whatever
Reply With Quote
  #7  
Old 11-21-2006
Tornado's Avatar
Registered User
 

Join Date: Nov 2006
Location: Melbourne
Posts: 243
Or just use ping..

# ping -s 192.168.1.1 2 2
PING 192.168.1.1: 2 data bytes
10 bytes from mercury (192.168.1.1): icmp_seq=0.
10 bytes from mercury (192.168.1.1): icmp_seq=1.

----192.168.1.1 PING Statistics----
2 packets transmitted, 2 packets received, 0% packet loss
#

This shows that IP 192.168.1.1 is mercury
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 06:51 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0