Monday, July 8, 2013

Sending and Receiving Data use Java socket programming

//java socket client example

public class socket_client
    public static void main(String[] args) throws IOException
        Socket s = new Socket();
    String host = "";
    PrintWriter s_out = null;
    BufferedReader s_in = null;
        s.connect(new InetSocketAddress(host , 6557));
        //writer for socket
            s_out = new PrintWriter( s.getOutputStream(), true);
            //reader for socket
            s_in = new BufferedReader(new InputStreamReader(s.getInputStream()));
        //Host not found
        catch (UnknownHostException e)
            System.err.println("Don't know about host : " + host);
        //Send message to server
    String message = "GET hosts\r\n\r\n";
    s_out.println( message );
    System.out.println("Message send");
    //Get response from server
    String response;
    while ((response = s_in.readLine()) != null)
        System.out.println( response );

Thursday, July 4, 2013

Bind livestatus unix socket to TCP socket use Python and twisted

from twisted.internet import protocol, reactor
import socket,os

socket_path = "/var/lib/nagios3/rw/live"

class Echo(protocol.Protocol):
    def dataReceived(self, data):
 s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)


 answer = s.recv(100000000)

class EchoFactory(protocol.Factory):
    def buildProtocol(self, addr):
        return Echo()

reactor.listenTCP(6557, EchoFactory())

Monday, July 1, 2013

One liner to download Oracle JDK with wget

wget --no-cookies --header "Cookie:;" --no-check-certificate -O jdk-7u25-linux-i586.tar.gz