python的socket库可以实现tcp和udp,在linux下unix socket也是可以的,有些程序在进程间通信就是使用unix socket,如果我们想查看其通信的信息来进行调试,则可以用python来伪造其接口,获取内容

参考:https://docs.python.org/2/library/socket.html



import socket
import os 
if __name__ == '__main__':     
    sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)  
    if os.path.exists('/tmp/UNIX.d'):  
        os.unlink('/tmp/UNIX.d')  
    sock.bind('/var/run/rrdcached.sock')     
    sock.listen(5)     
    while True:  
       connection,address = sock.accept()      
       print "Data : %s"%connection.recv(1024) 
       #connection.send("hello")  
       connection.close()


参考:http://www.2cto.com/os/201305/210033.html

bash下字符串操作: 

支持${parameter:offset:length},${parameter:offset}

 

igi@gentoo ~/test $ string='hello'

igi@gentoo ~/test $ echo ${string:1:3}

ell

igi@gentoo ~/test $ echo ${string:1}

ello

igi@gentoo ~/test $ echo $0

/bin/bash


dash: 不支持, 替代方法:采用expr或cut外部命令代替

 

$ string='hello'

$ expr substr "$string" 2 3

ell

$ echo "$string" | cut -c2-4

ell

$ expr substr "$string" 2 "${#string}"

ello

$ echo "$string" | cut -c2-

ello

$ echo $0

dash

$