Hi
I want to make a pure c++ application which is used to retrieve ip address of all connected users of LAN(local area network).
I am using Dev c++ IDE. please any buddy have any idea to solve this problem?
Thanks in advance!

you could just use ICMP ping on every possible ip on your lan.
(the subnet mask/broadcast address will give you this info. for example, use. >ifconfig -L http://www.freebsd.org/cgi/man.cgi?query=ifconfig&sektion=8 ).
even if the computer blocks ping (and everything else) you still get an entry in your arp cache.
you can then look at your arp cache ( with >arp -a ) to determine the ip addresses. http://www.freebsd.org/cgi/man.cgi?query=arp&sektion=8

if you are not on a routable net, this technique will not work. you would then need to use an ARP ping instead of an ICMP ping (and then dump your arp cache).
see http://www.habets.pp.se/synscan/programs.php?prog=arping (if you are on dev-c++ with minGW, download the windows version)

Thank you vijayan
I am using Dev c++ and want to retrieve all ip addresses of connected computer and their name through programming.I want to run this application on windows xp.
how i can do it? please reply me.

> I am using Dev c++
Dev c++ is just an ide; the compiler would be GCC, but the environment could be either CygWin or MinGW.
if you are using CygWin, install arping as per instructions here: http://mathieu.carbou.free.fr/wiki/index.php?title=How_to_compile_arping_under_Cygwin#Under_Cygwin
if you are using MinGW these are the instructions: http://mathieu.carbou.free.fr/wiki/index.php?title=How_to_compile_arping_under_Cygwin#Under_MinGW

once this is installed, you could use arping to send arp or icmp pings to hosts on the network. icmp pings will work only on routed networks, arp ping will work everywhere.

for example, if you are on a routed network where the ip addresses are in the range 192.168.2.0 to 192.168.2.255 (look at your subnet mask to see what it is for you), you could run the following shell script to discover ip addresses that are in use on your subnet. (this works on the unix shell or any shell conforming to POSIX.2. you will instead have something called bash. you may have to modify the script accordingly)

#!/bin/sh

seq() { echo "for (i=$1; i<=$2; i++) i;" | bc | tr "\012" " "; }

#this example is for: host ip 192.168.2.x netmask 0xffffff00

for a in $(seq 192 192); do
  for b in $(seq 168 168); do
    for c in $(seq 2 2); do
      for d in $(seq 0 255); do
        sh -c "arping -rRc 1 $a.$b.$c.$d >> iplist.txt
        if [ \$? = 0 ]; then
          echo Got answer with address: $a.$b.$c.$d
        fi" &
      done
    wait
    done
  done
done

this will place ( <mac-address>, <ip-address> ) tuples in the form 05:a4:e2:e0:17:8a 192.168.2.1 in the file iplist.txt, one tuple per line.
once you have the ip addresses, use the bsd sockets function gethostbyaddr http://fuse4bsd.creo.hu/localcgi/man-cgi.cgi?gethostbyaddr+3 to get the hostname(s) corrosponding to an ip address.

note: to execute a shell script from within your program use the standard c library function system .
if you want to do everything from within your code (without taking the help of a shell), rip off the necessary stuff from the source code for arping. (caveat: it is viral).

Thank you vijayan
I am working on windows xp and accordingly to you I need to install cygwin and its a lengthy process of downloading and installing. could you please give me some other solution.

if you are using Dev C++, you would already have either Cygwin or MinGW installed.

Yes vijayan i have installed dev c++ and mingw32 as a folder.

vijayan can you solve one thing for me i need to remove "//" this character from a char *str and want to convert it into string str1 how i can do.........??

> i need to remove "//" this character from a char *str
isn't "//" two characters? did you mean "\\" ?

const char* cstr = "abc\\def\\gh" ;
  std::string str = cstr ;
  std::string::iterator where =
        std::find( str.begin(), str.end(), '\\' ) ;
  if( where != str.end() ) str.erase( where ) ;

to erase all occurrences, put the above in a loop (break when where == str.end() )

Thanx a lot sir..... you are great.....
remaining part I will try to do if I will get problem than I will contact with you..
Thank you very much.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.