PYTHON
-
[Python] ping3 Module - divice ping checkSystem ManageMent 2019. 4. 26. 10:59
Homepage : https://github.com/kyan001/ping3 1. Install pip install ping3 2. Example from ping3 import ping, verbose_ping # Ping Check res = ping('192.168.1.99') # IP Or Domain print(res) ------------------------------------------------ 0.008645452999999997 # 4times ping check res = verbose_ping('192.168.1.99') print(res) ------------------------------------------------ ping '192.168.1.99' ... 5m..
-
[Python] Access Log 유니코드를 한글로 변환Python/Python Programming 2019. 4. 18. 19:02
access log 파일이나 한글 URL경로를 보면 한글이 유니코드로 표기되어 있다. python으로 이를 한글로 쉽게 변환이 가능하다. from urllib.parse import unquote_plus site = '.com/%EA%B3%A0%EB%93%B1-%EC%98%81%EC%96%B4' searchword = unquote_plus(site, encoding='utf-8', errors='replace') print(searchword) ------------------------------------------------------------------- .com/고등-영어
-
[Python] Linux에서 간단한 Web 모니터링 하기Python/Python for Linux 2019. 4. 15. 19:31
Python Version : 2.7.5 #!/usr/bin/python import requests as req from datetime import datetime import time sites = ('http://192.168.x.77','http://192.168.x.77/xxxx.php') for site in sites: try: r = req.get(site) print site, 'return_code :', r.status_code except Exception as e: print site, 'fail' time.sleep(10) ★ 웹 페이지가 기동 중 일 때, 아래와 같이 응답코드 값을 리턴 받을 수 있습니다. http://192.168.x.77 return_code : 200 (..
-
[Python] Linux Sendmail을 이용한 메일 보내기Python/Python for Linux 2019. 4. 13. 22:12
- OS : CentOS 7 - Python 2.7 #!/usr/bin/python from email.mine.text import MIMEText from subprocess import Popen, PIPE msg = MIMEText('Body Text') msg['Subject'] = 'Subject Text' msg['From'] = 'From Email Address' msg['To'] = 'To Email Address' p = Popen(["/usr/sbin/sendmail", "-t"], stdin=PIPE) p.communicate(msg.as_string()) Step 1. sendmail install # yum install sendmailyum install sendmail se..
-
[ CentOS ] Python pip installPython/Python for Linux 2019. 4. 13. 20:50
Step1. distribute zip download - https://pypi.org/project/distribute/#files # wget [ Link ] Step2. distribute zip download # unzip distribute-0.7.3.zip # cd distribute-0.7.3 # python setup.py install # easy_install pip # pip -V pip 19.0.3 from /usr/lib/python2.7/site-packages/pip-19.0.3-py2.7.egg/pip(python 2.7)
-
[Python] datetime.strftime를 이용한 날짜와 시간 변환Python/Python Programming 2019. 4. 11. 13:31
from datetime import datetime timenow = datetime.now() # Current Time dt = timenow.strftime('%m-%d-%Y, %H:%M:%S') # datetime print(dt) 04-11-2019, 13:20:17 year1 = timenow.strftime('%Y') # Year with century as a decimal number print(year1) 2019 year2 = timenow.strftime('%y') # Year without century as a zero-padded decimal number print(year2) 19 month1 = timenow.strftime('%m') # Month as a zero-p..
-
[Python] linux ping check(ICMP) programPython/Python for Linux 2019. 4. 9. 13:40
#!/usr/bin/python # Python Version : 2.7.5 from os import system from datetime import datetime checkList = ('127.0.0.1','192.168.x.99','192.168.x.98') logTime = str(datetime.today())[:19] for host in checkList: cmdstring = 'ping -c1 '+host+' 1>/dev/null' # Linux Ping Check Command var = system(cmdstring) if var == 0: # value = 0, OK print host, 'ping ok : ', logTime else: print host, 'ping fail ..
-
[Python] CentOS 7 Python3 Install and Symbolc linkPython/Python for Linux 2019. 3. 28. 14:29
1. Python Repository Install. (OS : CentOS 7) # yum install -y https://centos7.iuscommunity.org/ius-release.rpm 2. Python Install # yum install -y python36u python36u-libs python36u-devel python36u-pip 3. Install Complete # python3 -V Python 3.6.8 4. python3 and pip Symbolc link # ls -l /usr/bin/python /usr/bin/python -> python2 # rm /usr/bin/python rm: remove symbolic link ‘/usr/bin/python’? y ..