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 java.lang.String bindir
          this is where the nmap/nping/ncat compiled binaries should be stored.
static boolean canGetRoot
          tells us if "su" command is available
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
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
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  EditText mTarget
          Input area where user supplies scan target
static java.lang.String outputArgs
          the command to be executed (nmap, nping, ncat) and optional (and mandatory) command line arguments from mArguments
static ProgressDialog progressDialog
          Static so that the other classes can turn it off after it runs.
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.
static java.lang.String shellCmdLoc
          location of the 'su' command, if present, otherwise 'sh'.
private   sTask
          scanning engine thread
private   vTask
          verify installation thread
 
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, MI_DEBUG_EMAIL, MI_DEBUG_ENABLE, MI_EXIT, MI_MORE_HELP, MI_REINSTALL, MI_SURVEY, RUN_COMPLETE, RUN_ERROR, RUN_LINE, SCANTYPE_NCAT, SCANTYPE_NDIFF, SCANTYPE_NMAP, SCANTYPE_NPING, TAG, THREAD_ERROR
 
Constructor Summary
NmapMain()
           
 
Method Summary
private  void forceRestart()
          Added 0.4.7.
private  void initBindir()
           
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 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)
           
private  void saveUserEntry()
          Saves user preferences using the SharedPreferences.Editor object.
private  void showApkInfo()
          Print program version and SDK version to log.
private  void showWifiInfo()
          Try to get the SSID and IP.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

bindir

public static java.lang.String bindir
this is where the nmap/nping/ncat compiled binaries should be stored.


canGetRoot

public static boolean canGetRoot
tells us if "su" command is available


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


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


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


mTarget

private transient EditText mTarget
Input area where user supplies scan target


outputArgs

public static java.lang.String outputArgs
the command to be executed (nmap, nping, ncat) and optional (and mandatory) command line arguments from mArguments


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.


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.


shellCmdLoc

public static java.lang.String shellCmdLoc
location of the 'su' command, if present, otherwise 'sh'.


sTask

private transient  sTask
scanning engine thread


vTask

private transient  vTask
verify installation thread

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.


initBindir

private void initBindir()

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.


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)

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.


showWifiInfo

private void showWifiInfo()
Try to get the SSID and IP. If you get it, set the users title to reflect this information.