What is the best way to process command line arguments into variables? I'm trying to have a python script function such as this:
python file.py 192.168.1.48 8080
If no arguments are entered, it should print the following -
Usage: python file.py (ip address) (port)
So far here is my code. I haven't successfully got arguments to process properly as of yet. Please note this is merely proof of concept. I'm trying to get this working to develop another script. I want the command line arguments to populate the ip and port variables below with the user's input, and validate the input as IP address for ip variable and integer for port if possible. Any help is highly appreciated:
import urllib2
import ssl
ip="192.168.1.48"
port="8080"
ctx = ssl.create_default_context()
ctx.check_hostname = False
ctx.verify_mode = ssl.CERT_NONE
urllib2.urlopen("https://{0}:{1}".format(ip, port), context=ctx)