Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8952177
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T13:49:05+00:00 2026-06-15T13:49:05+00:00

I need to write a script to scan ports on server and generate a

  • 0

I need to write a script to scan ports on server and generate a report. This script should:

Read a list of IPs from a file;
Scan each IP, and write a file with the results.

I am using below script for this::

#!/usr/bin/perl -w
use strict;
use IO::Socket::PortState qw(check_ports);

my $hostfile = 'hosts.txt';

my %port_hash = (
        tcp => {
            22      => {},
            443     => {},
            80      => {},
            53      => {},
            30032   => {},
            13720   => {},
            13782   => {},
            }
        );

my $timeout = 5;

open HOSTS, '<', $hostfile or die "Cannot open $hostfile:$!\n";

while (my $host = <HOSTS>) {
    chomp($host);
    my $host_hr = check_ports($host,$timeout,\%port_hash);
    print "Host - $host\n";
    for my $port (sort {$a <=> $b} keys %{$host_hr->{tcp}}) {
        my $yesno = $host_hr->{tcp}{$port}{open} ? "yes" : "no";
        print "$port - $yesno\n";
    }
    print "\n";
}

close HOSTS;

Now I have 1 thing to do with is::

Scan for all open ports.

Currently it is scanning ports %port_hash but I need to scan all the ports and list ports which are open. How to do this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T13:49:07+00:00Added an answer on June 15, 2026 at 1:49 pm

    This will fill up %porthash with all the ports:

    my %port_hash = ( tcp => {} );
    for my $port (1 .. 65535) {
      $port_hash{'tcp'}{$port} = {};
    }
    

    Then you can call check_ports with this %port_hash.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to write a script in Matlab, which will read some data from
I need to write a script that disables SQL Server Express 2008 from running.
Need to write batch script which copies file from FTP to local drive I'm
I need to write a script that reads all the file names from a
I need to write a script for MS Exchange Server 2003 that will analyze
I need to write a script that can navigate through this ASP page: http://fcms.concordia.ca/fcms/asc002_stud_all.aspx
I need to write a script that will output data from a PostgreSQL database
I need to write a script to insert data selected from one table into
I need to scan a file system for a list of files, and log
I need to write a script to upload big Files (~2GB+) to a server.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.