com.wjholden.nmap
Class NmapMain

java.lang.Object
  extended by Activity
      extended by com.wjholden.nmap.NmapMain
All Implemented Interfaces:
NmapConstants

public class NmapMain
extends Activity
implements NmapConstants

Nmap for Android! The original versions used Nmap binaries I got from Robert McCurdy (http://rmccurdy.com/stuff/G1/BINS/NMAP/). Around v0.3 or Vlatko Kosturjak build newer binaries based on Nmap 5.3 (http://ftp.linux.hr/android/nmap/).

Version:
0.4.7
Author:
William John Holden (wjholden@gmail.com)

Field Summary
static boolean debug
          This variable is set by the user with the context menu.
private  boolean deletePreferences
          After reinstalling binaries, wipe the preferences.
static Handler handler
          handler for inter-thread communication
static boolean hasRunOneScan
          tells us whether one or more scans have been executed
private   installTask
          verify installation thread
static boolean installVerified
          if "VerifyInstallation()" method has run this should be set to true
private  EditText mArguments
          Input area where command-line arguments (other than target IP)
private  Spinner mCommandSpinner
          Command spinner switches between Nmap, Nping, and Ncat
private  Button mHelp
          Help button, shows result of [command] --help
private  Spinner mOutputSpinner
          Switches between Nmap, XML, and Grepable Nmap output
private  TextView mResults
          Text area where results are shown.
TODO: looks like Intent ACTION_VIEW has a neat feature to view a URL - would it be possible to create a URL based on a String, then view this value in fullscreen?
private  Button mShare
          Share button, launches Compose Email activity with message body of any data in mResults
private  Button mStart
          Start button initiates scan
private  Button mSubnet
          Launch NmapSubnet activity.
private  EditText mTarget
          Input area where user supplies scan target
private  java.lang.String outputGrep
          Instead of keeping old output on the filesystem, read it in and out as a String kept in memory.
private  java.lang.String outputNmap
          Instead of keeping old output on the filesystem, read it in and out as a String kept in memory.
private  java.lang.String outputXml
          Instead of keeping old output on the filesystem, read it in and out as a String kept in memory.
static ProgressDialog progressDialog
          Static so that the other classes can turn it off after it runs.
private   scanTask
          scanning engine thread
static int scanType
          tells the scanning engine what command is to be executed (nmap, nping, ncat)
private  SharedPreferences settings
          Store both user and application settings in here.
private  NmapWifi wifi
          Instance of thread where NmapWifi executes.
 
Fields inherited from interface com.wjholden.nmap.NmapConstants
BUFFER_SIZE, FORCE_RESTART, INSTALL_ERROR, INSTALL_FILENAMES, INSTALL_GOOD, INSTALL_NO_ROOT, INSTALL_RESOURCES, MG_DEBUG, MG_DEFAULT, MG_SUBNET, MI_BIN, MI_DEBUG_EMAIL, MI_DEBUG_ENABLE, MI_DEC, MI_EMAIL_SUBNET, MI_EXIT, MI_HEX, MI_MORE_HELP, MI_REINSTALL, MI_SUBNET, MI_SURVEY, RUN_COMPLETE, RUN_ERROR, RUN_SUCCESS_NO_FILE, SCANTYPE_NCAT, SCANTYPE_NDIFF, SCANTYPE_NMAP_5_30, SCANTYPE_NMAP_5_50, SCANTYPE_NPING, SET_TITLE, SUBNET_CONNECTED, SUBNET_DISCONNECTED, SUBNET_POLL_INTERVAL, TAG, THREAD_ERROR
 
Constructor Summary
NmapMain()
           
 
Method Summary
private  void forceRestart()
          Added 0.4.7.
private  void initButtons()
          AFTER initScreen() has been called, assign callbacks to buttons.
private  void initHandler()
          Initializes the handler.
private  void initScreen()
          Maps the buttons, text areas, and spinners to program variables.
private  void initSpinners()
          Initializes the spinners.
private  void initVariables()
          Use the Settings object to grab program variables from XML and set them appropriately.
 void onCreate(Bundle bundle)
           
protected  void onDestroy()
           
 boolean onMenuItemSelected(int featureId, MenuItem item)
           
protected  void onPause(Bundle outState)
           
 boolean onPrepareOptionsMenu(Menu menu)
           
protected  void onResume(Bundle bundle)
           
protected  void onStop()
           
private  void saveUserEntry()
          Saves user preferences using the SharedPreferences.Editor object.
private  void showApkInfo()
          Print program version and SDK version to log.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

debug

public static boolean debug
This variable is set by the user with the context menu. If on, use the Log utility to send debugging information to logcat, and also present user with a menu option to e-mail debugging output to developer.


deletePreferences

private boolean deletePreferences
After reinstalling binaries, wipe the preferences.


handler

public static Handler handler
handler for inter-thread communication


hasRunOneScan

public static boolean hasRunOneScan
tells us whether one or more scans have been executed


installTask

private transient  installTask
verify installation thread


installVerified

public static boolean installVerified
if "VerifyInstallation()" method has run this should be set to true

Since:
0.4.2 This and most other static variables here are saved in SharedPreferences so verifyInstallation only runs once.

mArguments

private transient EditText mArguments
Input area where command-line arguments (other than target IP)


mCommandSpinner

private transient Spinner mCommandSpinner
Command spinner switches between Nmap, Nping, and Ncat


mHelp

private transient Button mHelp
Help button, shows result of [command] --help


mOutputSpinner

private transient Spinner mOutputSpinner
Switches between Nmap, XML, and Grepable Nmap output


mResults

private transient TextView mResults
Text area where results are shown.
TODO: looks like Intent ACTION_VIEW has a neat feature to view a URL - would it be possible to create a URL based on a String, then view this value in fullscreen?


mShare

private transient Button mShare
Share button, launches Compose Email activity with message body of any data in mResults


mStart

private transient Button mStart
Start button initiates scan


mSubnet

private transient Button mSubnet
Launch NmapSubnet activity.


mTarget

private transient EditText mTarget
Input area where user supplies scan target


outputGrep

private transient java.lang.String outputGrep
Instead of keeping old output on the filesystem, read it in and out as a String kept in memory. This is for Nmap grepable output.

Since:
Added in version 27.

outputNmap

private transient java.lang.String outputNmap
Instead of keeping old output on the filesystem, read it in and out as a String kept in memory. This is for normal output.

Since:
Added in version 27.

outputXml

private transient java.lang.String outputXml
Instead of keeping old output on the filesystem, read it in and out as a String kept in memory. This is for XML output.

Since:
Added in version 27.

progressDialog

public static ProgressDialog progressDialog
Static so that the other classes can turn it off after it runs. This shall be the only ProgressDialog used. Don't use "new" - instead just change the text and show/hide it.


scanTask

private transient  scanTask
scanning engine thread


scanType

public static int scanType
tells the scanning engine what command is to be executed (nmap, nping, ncat)


settings

private transient SharedPreferences settings
Store both user and application settings in here.


wifi

private transient NmapWifi wifi
Instance of thread where NmapWifi executes.

Constructor Detail

NmapMain

public NmapMain()
Method Detail

forceRestart

private void forceRestart()
Added 0.4.7. Forces the activity to restart. Used after user has manually reinstalled binaries.


initButtons

private void initButtons()
AFTER initScreen() has been called, assign callbacks to buttons.


initHandler

private void initHandler()
Initializes the handler.


initScreen

private void initScreen()
Maps the buttons, text areas, and spinners to program variables.


initSpinners

private void initSpinners()
Initializes the spinners. Separated from initScreen() due to circular dependencies.

Since:
Added version 27.

initVariables

private void initVariables()
Use the Settings object to grab program variables from XML and set them appropriately.


onCreate

public void onCreate(Bundle bundle)

onDestroy

protected void onDestroy()

onMenuItemSelected

public boolean onMenuItemSelected(int featureId,
                                  MenuItem item)

onPause

protected void onPause(Bundle outState)

onPrepareOptionsMenu

public boolean onPrepareOptionsMenu(Menu menu)

onResume

protected void onResume(Bundle bundle)

onStop

protected void onStop()

saveUserEntry

private void saveUserEntry()
Saves user preferences using the SharedPreferences.Editor object. The actual settings are stored in an XML file within the application context. Checks deletePreferences variable to wipe preferences when user forces reinstallation.


showApkInfo

private void showApkInfo()
Print program version and SDK version to log.