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 02-23-2015, 03:38 PM   #1
doughyi8u
Member
 
Registered: Apr 2010
Posts: 254

Rep: Reputation: 10
printing to console in perl


I am having trouble getting the output from a hping3 command to the stdout. Here is what I have (a simplified version of the program I'm trying to write).

Code:
#!/usr/bin/perl -w

`hping3 -p 80 -S google.com`;
The program just hangs, outputting nothing to the screen. When I kill the command w/ ctrl + c I see the end of the command as if it were run on the console and not in a script. I tried it in a bash script too and it still just hangs.
 
Old 02-23-2015, 03:42 PM   #2
smallpond
Senior Member
 
Registered: Feb 2011
Location: Massachusetts, USA
Distribution: Fedora
Posts: 4,140

Rep: Reputation: 1263Reputation: 1263Reputation: 1263Reputation: 1263Reputation: 1263Reputation: 1263Reputation: 1263Reputation: 1263Reputation: 1263
Backticks capture stdout in the code, which you are then ignoring. Try:

Code:
system "hping3 -p 80 -S google.com";
 
Old 02-23-2015, 03:46 PM   #3
doughyi8u
Member
 
Registered: Apr 2010
Posts: 254

Original Poster
Rep: Reputation: 10
That did the trick.
 
Old 02-23-2015, 04:04 PM   #4
doughyi8u
Member
 
Registered: Apr 2010
Posts: 254

Original Poster
Rep: Reputation: 10
Another question:

How do I iterate through a block of addresses putting each result from the hping command to the terminal? Here's the code I have but it doesnt' do what I need. Is there a way to call ctrl +c from the program and start another iteration?

Code:
#!/usr/bin/perl -w

use Net::IP;

$addr = $ARGV[0];

my $ip = new Net::IP($addr) or die "Can't resolve ip address";

do {
    $addrs = $ip->ip();
    system "hping3 -S -p 80 $addrs";
} while (++$ip->ip);

return 0;

Last edited by doughyi8u; 02-23-2015 at 04:34 PM.
 
  


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
C advanced console printing sammoewel Programming 5 10-25-2008 06:31 AM
Printing from the console? mentallo Linux - Software 2 12-02-2005 02:40 PM
printing on the console balu14u Programming 5 04-06-2005 05:35 AM
Printing image from console theonebeyond Linux - Software 2 10-27-2004 04:36 AM
perl printing pantera Programming 1 06-02-2004 02:07 PM

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

All times are GMT -5. The time now is 04:12 AM.

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