Skip to content

Instantly share code, notes, and snippets.

@krispayne
Forked from sheagcraig/bring_the_payne.py
Last active May 4, 2017 21:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save krispayne/0ffa0af13e2a7422a5074836b57ced73 to your computer and use it in GitHub Desktop.
Save krispayne/0ffa0af13e2a7422a5074836b57ced73 to your computer and use it in GitHub Desktop.
Get IP Address for all computers in the JSS
#!/usr/bin/env python
"""https://twitter.com/krispayne/status/859833552078225408:
@shea_craig is possible with python-jss to generate a list of IP addresses for
computers in the JSS?
"""
from operator import itemgetter
# This example uses python-jss 2.0.0+
import jss
def main():
# Configure the JSS API object. Fill in with your information.
# You will need the add the JSS' certificate to your keychain and trust
# it.
j = jss.JSS(
url="https://jss.com:8443", user="python-jss", password="password",
ssl_verify=True)
# Alternate form, if you have built preferences already (see the docs):
# j = jss.JSS(jss.JSSPrefs())
# Query the JSS for all Computer objects. We use the subset argument to
# minimize the amount of data retrieved to just the 'general' data,
# which includes IP address.
#computers = j.Computer(subset='general')
computers = j.Computer()
# Build a list of the IP address value from each computer's general
# section. You can descend the tag tree with dot syntax notation.
ip_addresses = [comp.general.last_reported_ip.text for comp in computers]
# Get Departments
#departments = [comp.location.department.text for comp in computers]
# Show it!
print '[usermachines]'
for index, ip_address in enumerate(ip_addresses):
print ip_address
print
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment