-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGet-PACS-IPs.py
More file actions
29 lines (23 loc) · 823 Bytes
/
Get-PACS-IPs.py
File metadata and controls
29 lines (23 loc) · 823 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import os, subprocess, socket
# Number of workstations to Scan for
total_workstations = 5
# Save as csv file
logfile = open("PAC-IPs.csv", "w")
logfile.write("Hostname, IP\n")
# Get all IPs
with open(os.devnull, "wb") as limbo:
for i in range(total_workstations):
# Prefix - Create hostnames & Ping
hostname = "MCKNWKS"+str(i)
result = subprocess.Popen(["ping", "-n", "1", "-w", "200", hostname],stdout=limbo, stderr=limbo).wait()
# For offline hosts
if result:
logfile.write(hostname+",Offline\n")
print(hostname+" - Offline")
# Online hosts
else:
IP = (socket.gethostbyaddr(hostname))[2][0]
logfile.write(hostname+","+IP+"\n")
print(hostname+" -> "+IP)
logfile.close()
print ("\n\t - Done - \n")