Home  >  Support  >  Support Forum  >  Read ConnectPort X2's IP Address using Python
Welcome to Digi Forum, where you can ask questions and receive answers from other members of the community.

Read ConnectPort X2's IP Address using Python

0 votes

I am getting started with Digi's CP X2 and am trying to figure out a way to programatically read the gateway's IP address in python.

I tried using the SIOCGIFADDR method described here:

but it appears the X2 doesn't support the 0x8915 command in the fcntl.ioctl() call (Invalid argument error).

When I telnet into the gateway, I noticed the "display netdevice" command prints the IP address, so I might be able to run that command and parse the output. But it appears Python doesn't support the subprocess() or os.system() calls so that doesn't seem to work.

Has anyone figured out a way to obtain the gateway's IP address using python? Any ideas or suggestions would be very appreciated!
asked Jun 27 in 3rd Party Python and API development in other Languages by David22 New to the Community (0 points)

Please log in or register to answer this question.

2 Answers

0 votes
You can accomplish this by querying the settings via the Device Cloud. The following is an example Exported from the Device Cloud API Explorer found under the Documentation tab. You would fill in the items in bold as necessary. This will return all of the network settings, you would simply parse for the "ip":

# The following lines require manual changes
username = "YourUsername" # enter your username
password = "YourPassword" # enter your password
# This example establishes a https connection, but doesn't provide the server certificate validation.
# Production code should implement certificate validation.
import httplib
import base64

# create HTTP basic authentication string, this consists of
# "username:password" base64 encoded
auth = base64.encodestring("%s:%s"%(username,password))[:-1]

# message to send to server
message = """<sci_request version="1.0">
<send_message cache="false">
<device id="00000000-00000000-00409DFF-FFXXXXXX"/>
<rci_request version="1.1">
webservice = httplib.HTTPSConnection("login.etherios.com")

# to what URL to send the request with a given HTTP method
webservice.putrequest("POST", "/ws/sci")

# add the authorization string into the HTTP header
webservice.putheader("Authorization", "Basic %s"%auth)
webservice.putheader("Content-type", "text/xml; charset=\"UTF-8\"")
webservice.putheader("Content-length", "%d" % len(message))

# get the response
response = webservice.getresponse()
statuscode = response.status
statusmessage = response.reason
response_body = response.read()

# print the output to standard out
print (statuscode, statusmessage)
print response_body
answered Jun 27 by userid0 Veteran of the Digi Community (950 points)
Thank you very much for the quick answer!  Not to sound picky, but is there any local python solution I can use to avoid the device cloud subscription?

The "display netdevice" command has the IP address in the output.  There must be some way to locally obtain the IP address without going to the cloud (I hope!).
0 votes
I think you can open a socket at the port 23 and issue the required command, I have done this in java for CPX4 not sure in python. Give a try and check.
answered Jul 25 by 16ksa23 Veteran of the Digi Community (411 points)
Contact a Digi expert and get started today! CONTACT US