Networking Forums

Networking Forums > Computer Networking > Linux Networking > finding local ip

Reply
Thread Tools Display Modes

finding local ip

 
 
shyam
Guest
Posts: n/a

 
      02-20-2006, 02:13 PM
hi all

how do i find out the ip address of the local machine programatically?

thanks shyam

 
Reply With Quote
 
 
 
 
Bit Twister
Guest
Posts: n/a

 
      02-20-2006, 02:26 PM
On 20 Feb 2006 06:13:54 -0800, shyam wrote:
> hi all
>
> how do i find out the ip address of the local machine programatically?


You could parse it from
ifconfig
or ping -c 1 $(hostname)

I have a question for you. Your header has "Windows NT 5.0"
What is the Microsoft name of your operating system (NT, SE, XP Home,...) ?

 
Reply With Quote
 
Poly-poly man
Guest
Posts: n/a

 
      02-20-2006, 02:27 PM
shyam wrote:
> hi all
>
> how do i find out the ip address of the local machine programatically?
>
> thanks shyam
>

$hostname
$ping [what was given off by the hostname command]

poly-p man
 
Reply With Quote
 
shyam
Guest
Posts: n/a

 
      02-20-2006, 02:29 PM
i am looking for a way to do it using the unix socket functions

 
Reply With Quote
 
Bit Twister
Guest
Posts: n/a

 
      02-20-2006, 02:36 PM
On 20 Feb 2006 06:29:12 -0800, shyam wrote:
> i am looking for a way to do it using the unix socket functions


Answer my question and I will give another answer.

Your header has "Windows NT 5.0"
What is the Microsoft name of your operating system (NT, SE, XP Home,...) ?
 
Reply With Quote
 
Alan Gauton
Guest
Posts: n/a

 
      02-20-2006, 02:46 PM
In article <(E-Mail Removed)>,
(E-Mail Removed) says...
> On 20 Feb 2006 06:29:12 -0800, shyam wrote:
> > i am looking for a way to do it using the unix socket functions

>
> Answer my question and I will give another answer.
>
> Your header has "Windows NT 5.0"
> What is the Microsoft name of your operating system (NT, SE, XP Home,...) ?


Well, NT 5.0 is technically Windows 2000, but I can't remember what the
development name was (I know it wasn't Chicago or Longhorn though).

--
AG

Remove removes from address to remove anti-spam measures.
-----------------------------------------------------------------------
Alan Gauton E-Mail agauton @ postmaster.co.uk

Never for me the lowered banner, never the last endeavour!
(Damon Hill - 16th June 1999)
 
Reply With Quote
 
shyam
Guest
Posts: n/a

 
      02-20-2006, 02:48 PM
ya its windows 2000

 
Reply With Quote
 
Bit Twister
Guest
Posts: n/a

 
      02-20-2006, 02:58 PM
On Mon, 20 Feb 2006 14:46:22 -0000, Alan Gauton wrote:
> In article <(E-Mail Removed)>,
>>
>> Your header has "Windows NT 5.0"
>> What is the Microsoft name of your operating system (NT, SE, XP Home,...) ?

>
> Well, NT 5.0 is technically Windows 2000, but I can't remember what the


Ah, Windows 2000 is what I was after.

Thank you.
 
Reply With Quote
 
Bit Twister
Guest
Posts: n/a

 
      02-20-2006, 02:59 PM
On 20 Feb 2006 06:48:58 -0800, shyam wrote:
> ya its windows 2000


apropos gethost
man -k gethost
 
Reply With Quote
 
Toni Erdmann
Guest
Posts: n/a

 
      02-20-2006, 03:15 PM
shyam wrote:

> i am looking for a way to do it using the unix socket functions
>


Try using

socket(AF_INET,SOCK_DGRAM,0)
....

addr.sin_family = AF_INET;
addr.sin_addr.s_addr = INADDR_ANY;
addr.sin_port = 0;

bind( fd,(struct sockaddr*)&addr, sizeof(struct sockaddr_in) )
....


addr.sin_family = AF_INET;
addr.sin_addr.s_addr = inet_aton( ip-address of your DNS server );
addr.sin_port = 53;

connect( fd, (struct sockaddr*)&addr, sizeof(struct sockaddr_in) )
....
# yes you can connect a UDP socket, but no IP packets are transmitted
# then kernel finds the interface to use when sending to your DNS server
# the IP address of your DNS server is in /etc/resolv.conf
# but you should have problems finding /etc/resolv.conf in WinXX

getsockname( fd, (struct sockaddr*)addr, &retlen )

printf( "%s\n", inet_ntoa(addr.sin_adr.s_addr) );

# should then be the ip address if the interface


Not tested!

This is one solution, maybe not the best and will give you the
IP-address used when communicating with your DNS server.
There may be more IP-addresses assigned to your box, depending
on the number of NICs.

man socket
man bind
man connect
man getsockname
man inet_ntoa

should lead you further (on *x* systems, but not *X* like WinXP)

HTH
Toni
 
Reply With Quote
 
 
 
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Changing XP login from Local to Domain While Maintaining Local User. TomTech Windows Networking 13 10-03-2007 02:28 AM
how to create a local share on local computer muelle60 Windows Networking 10 10-04-2006 07:45 PM
Howto redirect traffic from local machine to internet back to local machine? Martin Kahlert Linux Networking 0 11-25-2005 08:40 AM
Finding who's on the network bigbrian Home Networking 4 01-27-2005 02:33 AM
finding ip address Sam Windows Networking 2 05-18-2004 05:53 AM



1 2 3 4 5 6 7 8 9 10 11