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 7845955
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T17:24:54+00:00 2026-06-02T17:24:54+00:00

I am developing an android port scanner but it doesn’t seem to be working.

  • 0

I am developing an android port scanner but it doesn’t seem to be working. Here’s the code for the PortScan class.

import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.net.UnknownHostException;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.TextView;

public class PortScan extends Activity
{

    String targetHost;

    /* Starting port for scan */
    public int startPort = 1;

    /* Ending port for scan */
    public int endPort = 100;

    /* Adapter for ListView */
    //private PortScanAdapter scanAdapter;

    /* Intent which invoked this class */
    private Intent scanIntent;

    /* Address of the host to scan */
    InetAddress targetAddress;

    /* Hostname of the target */
    String targetHostName;

    @Override
    protected void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);
        scanIntent = getIntent();
        prepareScan();
        setContentView(R.layout.port_scan_result);
        startScan();
    }

    private void prepareScan()
    {
        targetHost = scanIntent.getStringExtra("targetAddress");

        /* Get the IP Address of the target */
        try
        {
            targetAddress = InetAddress.getByName(targetHost);
        }
        catch(UnknownHostException e)
        {
            e.printStackTrace();
        }

        /* Get the hostname of the target */
        try
        {
            targetHostName = targetAddress.getHostName();
        }
        catch(Exception e)
        {
            targetHostName = targetHost;    
        }

       /*TextView hostName = (TextView)findViewById(R.id.host);
        hostName.setText(targetHostName); */
    }


    private void startScan()
    {
        /* Socket to connect to the remote machine */
        Socket portSocket;

        /* Textview which displays the scanresult */
        TextView scanText = (TextView)findViewById(R.id.portscanresult);

        scanText.setText("Scanning host "+ targetHost + "\n");

        for (int i = startPort; i == endPort; i++)
        {
            try
            {
                portSocket = new Socket();
                portSocket.connect(new InetSocketAddress(targetAddress, i), 1000);
                scanText.append("Target is listening on port "+ i + ": Port Open\n");
                portSocket.close();

            }   
            catch(Exception exception)
            {
                scanText.append("Target is not listening on port "+ i + ": Port Closed\n");
            }
        }
    }


}

I am testing this code on an emulator (Android 2.3.3). I don’t know whether the issue is with socket connections or TextView. When I run the program, the only output I get is the string before the for loop starts i.e "Scanning host "+ targetHost + "\n" and then nothing happens.

Any help will be greatly appreciated.

Regards

  • 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-02T17:24:55+00:00Added an answer on June 2, 2026 at 5:24 pm

    well … this is never going to work…

    for (int i = startPort; i == endPort; i++)
    

    The second is the condition if i==endport and i equals to startPort because you said so in the beginning… int i=startPort

    It has to be like this:

    for (int i = startPort; i <= endPort; i++)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

HI all, I'm just getting started with developing for Android. I'm looking to port
I just added some computationally expensive code to an Android game I am developing.
I am developing a project for an Android tablet which has USB port.In this
I know Java apps can be run in Android. But what I want to
I have been developing Android apps, but never did a live wallpaper. I have
I am developing android version of an iPhone application. But, I found that in
I am developing Android TextToSpeech app. This application is not working in Android 1.5
I'm very inexperienced when it comes to developing Android Applications and I cannot code
Possible Duplicate: Developing for Android in Eclipse: R.java not generating I have imported a
i am developing android messaging application i need to know port number of emulator

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.