Lots of times you need to determine your public IP address, if you are using Linux operating system to power your PC, you may use these one liners to find your IP -->
Using wget
|
Using curl
|
Using Lynx
[root@test ~]# lynx -dump checkip.dyndns.org OR [root@test ~]# lynx -dump www.whatismyip.com | grep 'Your IP Add' OR [root@test ~]# lynx -dump http://www.ip2location.com |grep -e 'IP Address' -e '\[_\] ' OR |
Though at any point of time you can open the browser and enter any of the following URL to the same effect but I would rather prefer to Unleash the power of Linux command lines/shell.Here are some examples of Python scripts which give the same result.
Using Python scripts as follows :--
#!/usr/bin/python import urllib import string import re f = urllib.urlopen("http://checkip.dyndns.org") s = f.read() f.close() pattern = re.compile('<body>(.*?)</body>',re.I|re.S) for each in pattern.findall(s): print each ================================================================== #!/usr/bin/python import lxml.html import string source = lxml.html.parse("http://www.minip.no") title_tag = source.find(".//title").text title = string.split(title_tag, " ") ip = title[3] print ip |
No comments:
Post a Comment