Posts

Showing posts from May, 2022

The IP_TRANSPARENT option of the socket implements the proxy

The socket has an IP_TRANSPARENT option, which is meant to enable a server program to listen to all IP addresses, even if they are not the local IP address, a feature that is very useful when implementing a transparent proxy server, and its use is simple: int int opt =1; setsockopt(server_socket,SOL_IP, IP_TRANSPARENT,&opt,sizeof(opt)); 0. Introduction: TCP binding 0.0.0.0 case TCP can bind 0.0.0.0, this is known, then in the end with which address when to determine it? The answer is "determined by doing a reverse route lookup based on the address of the connection source". If there is an address A connecting to that server, then after the server receives a syn, it looks up the route with destination address A and thus determines the source address, however if the IP_TRANSPARENT option is not set, then this connected address must be found in the local routing table or all bets are off. So if I have a TCP server without the IP_TRANSPARENT option bound to the address 0.0.0.

The easiest way to install iftop on Centos

yum -y install epel-release yum -y install iftop iftop -i eth0 -n

C language Hannota recursive implementation

C language Hannota recursive implementation void hanoi ( int n , char a , char b , char c ) { if ( n > 1 ) { hanoi ( n - 1 , a , c , b ) ; move ( a , c ) ; hanoi ( n - 1 , b , a , c ) ; } }

Calculate the bth power of a in C language

Calculate the bth power of a in C language long apowerb ( int a , int b ) { int i , r = 1 ; for ( i = 0 ; i < b ; i ++ ) { r * = a ; } return r ; }

Shell gets the absolute path of the directory where the script is located

Shell gets the absolute path of the directory where the script is located $( dirname $( readlink -f " $0 " ))

A simple way to send emails in Python

A simple way to send emails in Python # send mail #!/usr/bin/python # -*- coding: UTF-8 -*- import smtplib from email . mime . text import MIMEText from email . header import Header def sendEmail ( smtpServer , sendAddr , recvAddr , muser , mpass , sendSub , sendMsg ) : msg = MIMEText ( sendMsg , 'plain' , 'utf-8' ) msg [ 'From' ] = Header ( sendAddr , 'utf-8' ) msg [ 'To' ] = Header ( recvAddr , 'utf-8' ) msg [ 'Subject' ] = Header ( sendSub , 'utf-8' ) try : smtpObj = smtplib . SMTP ( ) smtpObj . connect ( smtpServer , 25 ) smtpObj . login ( muser , mpass ) smtpObj . sendmail ( sendAddr , recvAddr , msg . as_string ( ) ) return True except smtplib . SMTPException : return False sendEmail ( "smtp.qq.com" , "[email protected]" , [ '[email protected]' ] , "user1" , "password1" , "email-test!" , &q

Shell view the first and last N bytes of a file in binary format

Shell view the first and last N bytes of a file in binary format First 3 bytes:hexdump < file > | head -n 3 Last 3 bytes :hexdump < file > | tail -n 3

Linux find zombie processes by ps command

Linux find zombie processes by ps command ps -axo pid = ,stat = | awk ' $2 ~/^Z/ { print $1 }'

Shell changes the file name to lowercase

Shell changes the file name to lowercase for f in * do fn = ` basename $f ` nc = ` echo $fn | tr A-Z a-z ` if [ " $fn " != " $nc " ] ; then mv $fn $nc fi done

Shell converts all files in the current directory to Unix format

Shell converts all files in the current directory to Unix format find . -type f -name "*.txt" | xargs dos2unix -o

Shell statistics on current concurrent TCP/UDP/ICMP connections

Shell statistics on current concurrent TCP/UDP/ICMP connections netstat -apt | grep 'tcp' | grep ESTABLISHED | wc -l netstat -apt | grep 'udp' | grep ESTABLISHED | wc -l netstat -apt | grep 'icmp' | grep ESTABLISHED | wc -l

Find all factors of an integer in C language

Find all factors of an integer in C language void factor_calc ( int v ) { int i ; for ( i = 1 ; i <= v ; ++ i ) { if ( v % i == 0 ) { printf ( "%d " , i ) ; } } }