GMgKe586q6suSQnyqZLlGCooeWM

Pages

Search

Tuesday, May 3, 2011

Python - Pipe

>> import os
>> cmd = "dir"
>> fp = popen(cmd)
>> print fp.read()
>> fp.close()
Share/Bookmark

Python - anydbm Module

>> import anydbm
>> db = anydbm.open("data.db","c")
>> db["lady"] = "Gaga"
>> db["luna"] = "Maya"
>> print db["lady"]
Share/Bookmark

Mics - ub IP List

('dudde.ub.ac.id', '175.45.184.100')
('DI-PPTI', '175.45.184.101')
('mail.ub.ac.id', '175.45.184.111')
('simpeg.ub.ac.id', '175.45.184.116')
('hostingdosen.ub.ac.id', '175.45.184.118')
('external-gw.ub.ac.id', '175.45.184.129')
('internal-gw.ub.ac.id', '175.45.184.130')
('dmz-gw.ub.ac.id', '175.45.184.131')
('collo-gw.ub.ac.id', '175.45.184.132')
('inherent-gw.ub.ac.id', '175.45.184.138')
('proxy.ub.ac.id', '175.45.184.162')
('radius.ub.ac.id', '175.45.184.163')
('ns1.ub.ac.id', '175.45.184.164')
('ns2.ub.ac.id', '175.45.184.165')
('central-sw.ub.ac.id', '175.45.184.167')
('proxy2.ub.ac.id', '175.45.184.168')
('ldap.ub.ac.id', '175.45.184.170')
('lpse.ub.ac.id', '175.45.184.51')
('lpse-lat.ub.ac.id', '175.45.184.52')
('smtp-lpse.ub.ac.id', '175.45.184.55')
('simak-db.ub.ac.id', '175.45.184.57')
('siam-sv1.ub.ac.id', '175.45.184.58')
('esxi4.ub.ac.id', '175.45.184.59')
('blog.ub.ac.id', '175.45.184.60')
('devel-gw.ub.ac.id', '175.45.184.66')
('bais.ub.ac.id', '175.45.184.67')
('netmon.ub.ac.id', '175.45.184.68')
('www.ub.ac.id', '175.45.184.70')
('mail.ub.ac.id', '175.45.184.71')
('students-mail.ub.ac.id', '175.45.184.72')
('ftp.ub.ac.id', '175.45.184.73')
('ws.ub.ac.id', '175.45.184.75')
('siakad.ub.ac.id', '175.45.184.76')
('bridgedb.ub.ac.id', '175.45.184.77')
('siakad-db.ub.ac.id', '175.45.184.78')
('keudb.ub.ac.id', '175.45.184.79')
('sikeu.ub.ac.id', '175.45.184.80')
('smtp-gw.ub.ac.id', '175.45.184.81')
('lists.ub.ac.id', '175.45.184.82')
('inherent.ub.ac.id', '175.45.184.83')
('lecture.ub.ac.id', '175.45.184.85')
('siam.ub.ac.id', '175.45.184.86')
('hosting2.ub.ac.id', '175.45.184.87')
('hvm1.ub.ac.id', '175.45.184.89')
('selma.ub.ac.id', '175.45.184.90')
('hosting.ub.ac.id', '175.45.184.92')

Share/Bookmark

C++ - Building Manipulator

ostream &sep(ostream &stream){
    stream << '\t';
    return stream;
}
Share/Bookmark

Monday, May 2, 2011

C++ - Manipulaltion Output

    cout << "Table" << endl;
    cout << setw(15) << setiosflags(ios::left) << "Name";
    cout << setw(15) << setiosflags(ios::left) << "City";
    cout << setw(10) << setiosflags(ios::left) << "Age" << endl;

    string names[] = {"lady gaga","luna maya","aura kasih","barack obama"};
    string cities[] = {"new york","denpasar","jakarta","white house"};
    int ages[] = {24, 27, 25, 50};
    cout << "===================================" << endl;
    for(int i=0;i<4;i++){
        cout << setw(15) << setiosflags(ios::left) << names[i];
        cout << setw(15) << setiosflags(ios::left) << cities[i];
        cout << setw(10) << setiosflags(ios::left) << ages[i] << endl;
    }

Share/Bookmark

Python - Build Web Client

This is a small code for emulating on how to a web client connect to server:

file: client.py
import socket

HOST = 'localhost'
PORT = 6003
client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
client.connect((HOST, PORT))

# request line
http_data = 'GET /index.php HTTP/1.1\n'

# header line - all are optional but Host
http_data = http_data + 'Host: localhost:80\n'  # required
http_data = http_data + 'From: irfan.ub@gmail.com\n'
http_data = http_data + 'User-Agent: Lucia Browser\n'
http_data = http_data + 'Keep-Alive: 10\n'
http_data = http_data + 'Accept: text/html\n'
http_data = http_data + 'Connection: close\n'

# separation line - required
http_data = http_data + '\n'    # required

client.send(http_data)

data = client.recv(1024*5)
client.close()
print 'Received\n=================\n', data

The response header is like this:
Received
=================
HTTP/1.1 200 OK
Date: Sun, 01 May 2011 22:19:28 GMT
Server: Apache/2.2.14 (Win32) DAV/2 mod_ssl/2.2.14 OpenSSL/0.9.8l mod_autoindex_
color PHP/5.3.1 mod_apreq2-20090110/2.7.1 mod_perl/2.0.4 Perl/v5.10.1
X-Powered-By: PHP/5.3.1
Set-Cookie: PHPSESSID=ajunliavga128hlvcou4chigv6; path=/
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
Content-Length: 114
Connection: close
Content-Type: text/html

<form action="test.php" method="post">
<input type="text" name="text"/> Holla</form>
<a href="test.php">Test</a>
Share/Bookmark

Python - Bulding Web Server

Here's a short code on how to build workable web server:

name: server.py
import socket

HOST = ''
PORT = 6003

server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server.bind((HOST, PORT))
server.listen(2)
conn, addr = server.accept()

print 'Connected by', addr

# initial lines
data = 'HTTP/1.0 404 Not Found\n'

# header lines - all are optional
data = data + 'Date: Fri, 31 Dec 2011 10:12:13 GMT\n'
data = data + 'Content-Type: text/html\n'
data = data + 'Content-Length: 22\n'
data = data + 'Server: Lucia Web Server\n'

# separating lines. needed
data = data + '\n'

# body
data = data + '<html><head><title>Hello World</title></head><body>'
data = data + '<h1>hello World</h1></body></html>'

# receiving the request headers from browser
datas = conn.recv(1024)
print datas


# send the response header plus the body
conn.send(data)
conn.close()



These the request header of the browser:

GET /index.html HTTP/1.1
Host: localhost:6003
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.17) Gecko/2
0110420 SVD Firefox/3.6.17
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 115
Connection: keep-alive


Accessed from telnet
>>telnet
telnet>> open localhost 6003 HTTP/1.0 /index.hmtl

Share/Bookmark