This article mainly introduces the Python language for obtaining information about the host name killing process based on the port. For more information, see: Using python to detect the active port of the host and check the active host.
We will share with you the code for using the python language to obtain the Host Name and kill the process based on the port.
Ip = OS. popen ("ifconfig eth0 | grep 'inet addr '| awk-F':'' {print $2}' | awk '{print $1 }'") ip = ip .. read (). strip () pid = OS. popen ("netstat-anp | grep 8998 | awk '{print $7 }'"). read (). split ('/') [0] OS. popen ('Kill-9 {0 }'. format (int (pid )))
The following describes how to kill_process.py uses a pid to kill the corresponding process. The code for kill_process.py is as follows:
#! /Usr/bin/python #-*-coding: UTF-8-*-import osimport sysimport signaldef kill (pid): try: a = OS. kill (pid, signal. SIGKILL) # a = OS. kill (pid, signal.9) # process equivalent to print 'killed pid % s, return value: % s' % (pid, a) failed t OSError, e: print 'no such process !!! 'If _ name _ = '_ main _': kill (8132) OK, Enjoy it !!!