The Python language obtains the Host Name and kills the process based on the port. The python Host Name
Recommended: Use 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 !!!
Articles you may be interested in:
- Python: Getting Windows or Linux host names and sharing common functions
- Python implements reverse Host Name Lookup Based on IP addresses
- How to obtain all IP addresses by host name in python