Advertisement
Guest User

Untitled

a guest
May 6th, 2017
579
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. #!/usr/bin/env python
  2. import sys
  3. import socket
  4. import smtplib
  5. import time
  6. import string
  7.  
  8. password='testtest'
  9. hostlist='/home/januszeal/monitor/list.csv'
  10.  
  11. h=open(hostlist,'r')
  12. hostlist=h.readlines()
  13.  
  14. for fml in hostlist:
  15. hostarray=fml.split(',')
  16. host=hostarray[0].rstrip('\r').rstrip('\n')
  17. # cool data types bro
  18. port=int(hostarray[1].rstrip('\r').rstrip('\n'))
  19. sock=socket.socket()
  20. timestamp=time.strftime("%Y/%m/%d %H:%M:%S", time.localtime())
  21. try:
  22. sock.connect((host,port))
  23. except:
  24. msg='<'+timestamp+'> Connect to host '+host+' on port '+str(port)+' [FAIL]'
  25. server = smtplib.SMTP('smtp.gmail.com:587')
  26. server.starttls()
  27. server.login(username,password)
  28. server.sendmail(fromaddr, toaddrs, msg)
  29. server.quit()
  30. print('<'+timestamp+'> Connect to host '+host+' on port '+str(port)+' [\x1b[0;31mFAIL\x1b[m]')
  31. else:
  32. print('<'+timestamp+'> Connect to host '+host+' on port '+str(port)+' [\x1b[0;32mPASS\x1b[m]')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement