LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-13-2010, 08:07 PM   #1
LazerPhreak
Member
 
Registered: Dec 2009
Location: USA
Distribution: Ubuntu Server / Desktop / UNR
Posts: 117

Rep: Reputation: 17
C++. How to make pinging program more efficient.


I am starting a project of my own (and learning C++ at the same time...bad idea? I dont think so yet...lol) I got my program to successfully scan a custom netmask, but it is REALLY slow. I want my program to do something similar to nmap -sP xxx.xxx.xxx.xxx-xxx. Any ideas on how to speed it up? Such as pinging more than one IP at a time...

Code:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <sstream>

using namespace std;
int ip42;
string ip1, ip2, ip3, ip4, ipaddr;
int main()
{

    cout << endl << "Enter part 1: ";
    cin >> ip1;
    cout << endl << "Enter part 2: ";
    cin >> ip2;
    cout << endl << "Enter part 3: ";
    cin >> ip3;
    cout << endl << "Enter part 4: ";
    cin >> ip4;
while(ip42 < 255){
    ipaddr = string("ping -c 1 ").append(ip1);
    ipaddr = string(ipaddr).append(ip2);
    ipaddr = string(ipaddr).append(ip3);
    ipaddr = string(ipaddr).append(ip4);
    system(ipaddr.c_str());
    ip42 = atoi(ip4.c_str());
    ip42 += 1;
    stringstream output;
    output << ip42;
    output >> ip4;
}
}

Last edited by LazerPhreak; 03-13-2010 at 08:09 PM.
 
Old 03-13-2010, 08:16 PM   #2
smeezekitty
Senior Member
 
Registered: Sep 2009
Location: Washington U.S.
Distribution: M$ Windows / Debian / Ubuntu / DSL / many others
Posts: 2,339

Rep: Reputation: 231Reputation: 231Reputation: 231
system() is quite slow and exec() would be faster.
 
0 members found this post helpful.
Old 03-14-2010, 04:43 AM   #3
Maligree
Member
 
Registered: Mar 2008
Distribution: Gentoo, CentOS, Fedora, Arch
Posts: 231
Blog Entries: 1

Rep: Reputation: 42
Threading, dude, threading.
 
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Next step to make this script more efficient...? redlinuxxx Programming 2 10-01-2009 09:42 AM
can i make a script or program make a phone call? nephish Linux - Software 2 08-15-2005 09:02 PM
i make a program using forte how can i generate from that program an rpm abdelhlims Programming 0 07-13-2004 12:10 PM
how to make a c/c++ program? guni Programming 7 10-20-2003 11:40 AM
help this to make this sed efficient plz doublefailure Programming 1 03-25-2002 06:57 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:09 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration