First, find out the IP addr command result in the native all IPV4 address
Bash:
grep ' (?:\ D+\.) {3}\d+/\d+'127.0. 0.1/8172.18. 16.4/
Python3:
[Email protected] ~/py $ cat ipaddr.py#!/usr/bin/python3#-*-coding= ' utf-8 '-*-ImportReImportSUBPROCESSIPB= Subprocess.check_output ('IP Addr', shell=True) ipaddr= Ipb.decode ('Utf-8') Ip1,ip2= Re.findall (r'(?:\ D+\.) {3}\d+/\d+', ipaddr)Print(IP1, IP2) [email protected]~/py $ python3 ipaddr.py127.0.0.1/8 172.18.16.4/24
Ii. list the three partitions with the largest inode utilization, listing the partition name, Inode usage
Bash:
DF sed ' s/+//g ' cut -D' -f1,5sorthead -n33 1%1
Python3:
[Email protected] ~/py $ cat df.py#!/usr/bin/env Python3#-*-coding=utf-8-*-ImportReImportsubprocessImportHeapqa= Re.split ('\ n', Subprocess.getoutput ('df-i')) b=[]c= [] forXinchA[1:]: Z= Re.split ('\s+', X, 5) B.append (z[0]) c.append (z[-2]) d=dict (Zip (b,c))Print(Heapq.nlargest (3, D.items (), key=LambdaX:x[1])) [email protected]~/py $ python3 df.py [('/dev/root','3%'), ('SHM','1%'), ('Tmpfs','1%')]
Third, find the UID maximum user name, UID, SHELL
Bash:
Sort ' : ' 3 passwd Head 1 Cut ' : ' ' 1,3,7 ' Nobody: 65534:/bin/false
Python3:
[Email protected] ~/py $ cat pw.py#!/usr/bin/env Python3#_*_ coding:utf-8 _*_ImportRewith Open ('/home/f/py/passwd','R') as F:a=F.readlines () b= [] forXincha:b.append (Re.split (':', X)) C= Max (b, key=LambdaS:int (s[2])) Name,_,uid,*_,shell =CPrint(name, UID, Shell.strip ()) [email protected]~/py $ python3 pw.py Nobody65534/bin/false
Iv. identify the permissions of/tmp and display them digitally
Bash:
Stat sed ' 4p ' grep ' (? <=\ () \d{3,4} (? =/)'1777
Python3:
[Email protected] ~/py $ cat tmpperm.py#!/usr/bin/env Python3#-*-coding=utf-8-*-ImportReImportSubprocessa= Re.split ('\ n', Subprocess.getoutput ('stat/tmp')) [3]Print(Re.findall ('(? <=\ () \d{3,4} (? =/)', a)) [Email protected]~/py $ python3 tmpperm.py ['1777']
V. Count the number of remote host IPs currently connected to the local computer and arrange them from large to small
Python3&bash:
# cat ss.py && python3 ss.py&& Ss-tun | grep-op ' (?: \ D+\.) {3}\d+ (? =:\d+\s*$) ' | Sort | uniq-c | Sort-nr
#!/usr/bin/env Python3#-*-coding= ' utf-8 '-*-ImportReImportSubprocessa= Re.findall (r'(?:\ D+\.) {3}\d+ (? =:\d+\s*)', Subprocess.getoutput ('Ss-tun')) [1::2]b=set (a) C= [] forXinchB:c.append (A.count (x)) d=dict (Zip (b,c))Print(Sorted (D.items (), key=LambdaZ:Z[1], reverse=True))
Python3 output:
[('74.125.23.102', 3), ('42.121.254.229', 2), ( ' 74.125.23.100 ', 1), ('220.181.105.153', 1)]
Bash output:
3 74.125.23.102 2 42.121.254.229 1 74.125.23.100 1 220.181.105.153
Linux Basic Notes--[004]--8 month 4th after class homework