Shammer's Philosophy

My private adversaria

Python

My python2 pocket reference - 20151214

This is updated version of python2 pocket reference from http://d.hatena.ne.jp/shammer/20151212/p1. Added substring from some index to last. Conditions There is no syntax like switch, case, cond. Only if-elif-else is available. >>> X = 100…

My python2 pocket reference - 20151212

This is a first version of python2 pocket reference. Conditions There is no syntax like switch, case, cond. Only if-elif-else is available. >>> X = 100 >>> if X == 10: ... print 'X is 10' ... elif X == 20: ... print 'X is 20' ... else: ...…

UDP Echo Client ver 20150816

My latest UDP Echo Client is written in this article. This client has informations about destination UDP Server, but it is more better to pass the destination informations as command line arguments. Today's client is upgraded based on this…

Python UDP Echo Server ver 20150813

This is an upgraded version of my python UDP Echo Server written in UDP Echo Server with python version 20150802 - Shammerism. Adding argparse and this version can be set listen port as the command line argument. #!/usr/bin/env python impo…

UDP Echo Server with python version 20150802

This is a upgraded python echo server of UDP Server by Python - Shammerism. Upgraded point is server side message to include client socket information. #!/usr/bin/env python import socket from contextlib import closing from time import cti…

SSL Server Cipher Check Client with python

I wrote similar scripts which I will write in this article. The latest one of those is Python SSL Client for checking ciphers supported on the server - Shammerism. This version can be check only one cipher at one execution, but I wrote the…

Python SSL Client for checking ciphers supported on the server

This is an upgraded script of Python SSL Client disabled server certificate verification - Shammerism. The ssl socket generated by httplib.HTTPSConnnection can be initialized with the SSL Context. Then, we can define the cipher to be able …

Multi Thread Infinite KeepAlive Simple HTTP Server with python socket library

This is an update of Infinite KeepAlive Simple HTTP Server with python socket library - Shammerism with conbined the content of Using Python Thread - Shammerism. #!/usr/bin/env python import argparse import socket import threading from soc…

Python SSL Client disabled server certificate verification

Sample code I wrote same as above in Remote SSL Server cipher check script with python - 20150130 - Shammerism. In this article, I used socket library but I can't completely disable server certificate verification. But, httplib can do this…

Using Python Thread

Python supports thread execution. This is so similar with Java. Inherit Thread class and override run method Mapping some function to Thread and start that Thread Inherit Thread class #!/usr/bin/env python import threading class MyThread(t…

Infinite KeepAlive Simple HTTP Server with python socket library

In Python Socket Server with socket library - Shammerism, I wrote a simple http server with python. This always returns same response and HTTP Request parsing is not sufficient. And there are a lot of lacks, this should be used only for te…

Python Socket Server with socket library

I wrote python socket server in Python Socket Server - Shammerism, but this is using SocketServer. This can't be changed flexibly so I write again with socket library. #!/usr/bin/env python import argparse import socket from socket import …

Python Collection 20150301

This is a next version of Python Collection 20150209 - Shammerism. Adding argparse examples. If-else if x > 0: print "X is bigger than 0." else: print "X is less than 0." If-elif-else if x > 0: print "X is bigger than 0." elif x == 0: prin…

Python most basic FIN handling

Almost computer languages can handle socket that enables connecting other hosts or listening from other hosts. And a user should master how to handling sockets via those APIs, like opening a listen port, connecting other hosts, closing soc…

Python Collection 20150209

Recently, the case using python is getting more and more gradually. But, I have used python not high frequently so I forget a lot of things and whenever I look for the way how to write basic python code. It is not reasonable. So I begin co…

Remote SSL Server cipher check script with python - 20150130

Debian wheezy has python 2.7.3 and it's SSL library looks disabling server-certificate-verify as default. The script I wrote at Remote SSL Server cipher check script with openssl - 20150126 - Shammerism uses openssl and there is no way to …

Send HTTP Request with python

Before I wrote python http client with python socket in this article, but this is not a socket version, using httplib. GET connection = httplib.HTTPSConnection(host) connection.request("GET", uri) response = json.loads(connection.getrespon…

Apache python inline CGI

Python sample code is here. This source code file extension should be .py and located in /usr/lib/cgi-bin/ directory and attached exec permission by chmod 755 ***.py(*** means file name). import cgi print "Content-Type: text/html" # This i…

UDP Server by Python

シンプルな実装だが、メモ的な目的で記載。 #!/usr/bin/env python from time import ctime import socket from contextlib import closing def main(): host = '192.168.1.10' port = 12345 bufsize = 4096 sock = socket.socket(socket.AF_INET, socket.SO…

UDP send client with sticky source port

UDP send client - Shammerismでは、単にデータを送るというだけのクライアントを書いた。しかし、稀に送信ポートを固定したいと思うときがあるので、それを実現するように一行ばかり追加した。サーバーと同じように、bind してやればいい。 import socket i…

UDP send client

python で UDP データを送るサンプル。宛先IPとポート、送るデータサイズのみオプション指定できるようにしてみました。 #!/usr/bin/env python import socket import argparse import time from contextlib import closing parser = argparse.ArgumentParse…

Python でファイルを読み込み

簡単な例だがメモ。 >>> f = open('test-text.txt') >>> data = f.read() >>> f.close() >>> lines = data.split('\n') >>> print lines ... Python もいずれは IO function 集みたいなのを書いておいた方がいいかも。 さらに、読み込んだ行に特定の文字が含…

Python Socket Server

Python HTTP Post client - Shammerismでクライアントを書いたので、今度はサーバー。と言っても、複雑なことは何もせず決まった応答を返すだけのもの。ほとんどサンプルのコピー。。。 import SocketServer class MyTCPHandler(SocketServer.BaseRequestHan…

Python に冗長なコードを出力してもらう

問題点 オブジェクト指向でコードを書いていて退屈してくるのが ValueObject の記述。フィールドがあって、そのフィールドに対するアクセサを書く。2 つとか 3 つくらいならいいけれども、フィールドが 10 とかあるとうんざりしてくる。しかも同じようなコー…

Python HTTP Post client

とりあえず、、、そろそろ Python も触ってみようかと思って書いてみた。たいしたことはやっていないけれども。とりあえずこれだけ。 KeepAlive & Content-Length import socket HOST = '10.0.0.1' port = 80 POST_DATA = "username=administrator" client =…