Skip to content

Commit

Permalink
Lsof and tcpdump: Add demo.
Browse files Browse the repository at this point in the history
  • Loading branch information
atlas-comstock committed Feb 8, 2016
1 parent b2f334e commit d0e09ff
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -145,14 +145,16 @@ protected void StartSniff(List<Program> transfer_list_program, boolean is_Checke
EditText edittext = (EditText) findViewById(R.id.seconds_duration);
String toParse = edittext.getText().toString();
int seconds_duration = 0;
if(toParse != "" && toParse != null)
seconds_duration = Integer.parseInt(toParse);
Log.d("parse", toParse);
// if(toParse != "" && toParse != null)
// seconds_duration = Integer.parseInt(toParse.replaceAll("\\D+","").replaceAll("\r", "").replaceAll("\n", "").trim(),10);
socket_sniff.SetSecondsDuration(seconds_duration);
edittext = (EditText) findViewById(R.id.len_of_packet_capture);
toParse = edittext.getText().toString();
int len_of_packet_capture = 0;
if(toParse != "" && toParse != null)
len_of_packet_capture = Integer.parseInt(toParse);
Log.d("parse", toParse);
// if(toParse != "" && toParse != null)
// len_of_packet_capture = Integer.parseInt(toParse.replaceAll("\\D+","").replaceAll("\r", "").replaceAll("\n", "").trim(),10);
sniffpackets.SetLenOfPacketCapture(len_of_packet_capture);

start_button.setEnabled(false);
Expand All @@ -167,6 +169,7 @@ protected void StartSniff(List<Program> transfer_list_program, boolean is_Checke
}



private static boolean isWifi(Context mContext) {
ConnectivityManager connectivityManager = (ConnectivityManager) mContext
.getSystemService(Context.CONNECTIVITY_SERVICE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,9 @@ protected void StartSocketSummary() {
}

protected void AndroidLsof() {
RootCmd("date +%s >> /data/data/com.example.yonghaohu.sniff/files/lsofres");
RootCmd("/data/data/com.example.yonghaohu.sniff/" +
"files/./androidlsof -i -F ctPf 2>&1 >> /data/data/com.example.yonghaohu.sniff/" +
"files/lsofres");
RootCmd("date +%s >> /data/data/com.example.yonghaohu.sniff/files/lsofres;"+
" /data/data/com.example.yonghaohu.sniff/files/./androidlsof +c 0 -i -F ctPnf 2>&1"
+" >> /data/data/com.example.yonghaohu.sniff/" + "files/lsofres");
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,7 @@ public void run() {
*/
public void startTCPdump() {
if (true) {//tcpDumpHandler.checkNetworkStatus()

switch (tcpDumpHandler.start("-i any -p -s " + lenOfPacketCapture)) {
switch (tcpDumpHandler.start(lenOfPacketCapture)) {
case 0:
Toast.makeText(mycontext, (R.string.tcpdump_started),
Toast.LENGTH_SHORT).show();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,12 +214,10 @@ public String RootCmd(String cmd){
* -4 Error when running the TCPdump command.<br>
* -5 Error when flushing the DataOutputStream.
*/
public int start(String params) {
public int start(int params) {
// SecondActivity secondActivity = new SecondActivity();

if(RootCmd("/data/data/com.example.yonghaohu.sniff/" +
"files/tcpdump > /data/data/com.example.yonghaohu.sniff/" +
"files/tcpdumpres ") == "false") {
if(RootCmd("/data/data/com.example.yonghaohu.sniff/files/tcpdump "+"-v -s "+params+
" -w /data/data/com.example.yonghaohu.sniff/files/tcpdumpres") == "false") {
Toast.makeText(mContext, ("RootCmd false"),
Toast.LENGTH_SHORT).show();
return 0;
Expand Down

0 comments on commit d0e09ff

Please sign in to comment.