Posts Tagged ‘Remote’
28
May

Steps

1) Create a project named Test4 and package name com.Test4.pack

2) Type code as below,

Test4.java

package com.Test4.pack;
import android.app.Activity;
import android.os.Bundle;
// used for interacting with user interface
import android.widget.Button;
import android.widget.TextView;
import android.widget.EditText;
import android.view.View;
// used for passing data
import android.os.Handler;
import android.os.Message;
// used for connectivity
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;

public class Test4 extends Activity {
/** Called when the activity is first created. */

Handler h;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

final EditText eText = (EditText) findViewById(R.id.address);
final TextView tView = (TextView) findViewById(R.id.pagetext);

this.h = new Handler() {

@Override
public void handleMessage(Message msg) {
// process incoming messages here
switch (msg.what) {
case 0:
tView.append((String) msg.obj);
break;
}
super.handleMessage(msg);
}
};
final Button button = (Button) findViewById(R.id.ButtonGo);
button.setOnClickListener(new Button.OnClickListener() {
public void onClick(View v) {
try    {
tView.setText("");
// Perform action on click
URL url = new URL(eText.getText().toString());
URLConnection conn = url.openConnection();
// Get the response
BufferedReader rd = new BufferedReader(new
InputStreamReader(conn.getInputStream()));
String line = "";
while ((line = rd.readLine()) != null) {
Message lmsg;
lmsg = new Message();
lmsg.obj = line;
lmsg.what = 0;
Test4.this.h.sendMessage(lmsg);
}
}
catch (Exception e)    {
}
}
});
}
}

main.xml

<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > <EditText android:layout_height="wrap_content" android:id="@+id/address" android:layout_width="fill_parent" android:text="http://google.com" > </EditText> <Button android:id="@+id/ButtonGo" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="go!" > </Button> <TextView android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="#ffffff" android:textColor="#000000" android:id="@+id/pagetext" /> </LinearLayout>
3)  Insert the below code in manifest.xml after </application>
<uses-permission android:name="android.permission.INTERNET"></uses-permission>

4) Run the application, You will get result as below

, , , , , , , , , , , , , , , , , , , , ,

16
Apr

Create a PHP CLI script called monitor.php like this

  1. #!/usr/bin/php -q
  2. <?php
  3. define ( TIMEOUT , 30 ) ;
  4. define ( EMAIL , ‘ abc @ youremail . com ) ;
  5. check ( http://hosta.com ) ;
  6. check ( http://hostb.com ) ;
  7. check ( http://hostc.com ) ;
  8. check ( http://hostd.com ) ;
  9. function check ( $url ){
  10. $ch = curl_init () ;
  11. curl_setopt ( $ch , CURLOPT_RETURNTRANSFER , 1 ) ; // Return Page contents.
  12. curl_setopt ( $ch , CURLOPT_URL , $url ) ;
  13. curl_setopt ( $ch , CURLOPT_TIMEOUT , 30 ) ;
  14. curl_setopt ( $ch , CURLOPT_DNS_CACHE_TIMEOUT , TIMEOUT ) ;
  15. curl_setopt ( $ch , CURLOPT_CONNECTTIMEOUT , TIMEOUT ) ;
  16. curl_setopt ( $ch , CURLOPT_HEADER , TIMEOUT ) ;
  17. $result = curl_exec ( $ch ) ;
  18. curl_close ( $ch ) ;
  19. // HTTP/1.1 200 OK”)
  20. if ( strpos ( $result , 200 OK ) != 8 ){
  21. mail ( EMAIL , Error in $url , $results ) ;
  22. }
  23. }
  24. ?>

Add this line in your Linux /etc/crontab or via cpanel to monitor eg: every 3 minutes

*/3 * * * * root /usr/sbin/monitor.php >> /dev/null 2>&1

, , , ,