| | |
Getting the connected user's ip in python
Please support our Python advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved |
Hi there,
Trying to write a small script in python. What it will basically do is this;
1- A SSH user initiates the python script (from SSH remotely)
2- The script gets the connected users IP (the user is connected through SSH)
3- The connected IP is sent back to the user
I got the part where the user initiates script (the easiest part so far)
I also got to write to a file and send the same file using SSH and Python
The part I need help is in the step 2
I am a first time Python programmer. Been using it for three days so be kind to me please ^_^
Trying to write a small script in python. What it will basically do is this;
1- A SSH user initiates the python script (from SSH remotely)
2- The script gets the connected users IP (the user is connected through SSH)
3- The connected IP is sent back to the user
I got the part where the user initiates script (the easiest part so far)
I also got to write to a file and send the same file using SSH and Python
The part I need help is in the step 2
I am a first time Python programmer. Been using it for three days so be kind to me please ^_^
"By the data to date, there is only one animal in the Galaxy dangerous to man—man himself. So he must supply his own indispensable competition. He has no enemy to help him."
From Time Enough for Love by Robert A. Heinlein
From Time Enough for Love by Robert A. Heinlein
0
#2 Oct 28th, 2009
to get your computers ip, try
python Syntax (Toggle Plain Text)
>>> import socket >>> socket.gethostbyname(socket.gethostname())
0
#3 Oct 28th, 2009
•
•
•
•
to get your computers ip, try
python Syntax (Toggle Plain Text)
>>> import socket >>> socket.gethostbyname(socket.gethostname())
Or does it give the IP of the machine that calls it?
"By the data to date, there is only one animal in the Galaxy dangerous to man—man himself. So he must supply his own indispensable competition. He has no enemy to help him."
From Time Enough for Love by Robert A. Heinlein
From Time Enough for Love by Robert A. Heinlein
0
#4 Oct 28th, 2009
•
•
•
•
to get your computers ip, try
python Syntax (Toggle Plain Text)
>>> import socket >>> socket.gethostbyname(socket.gethostname())
I know that 127.0.0.1 is localhost but what is 127.0.0.2 ?
"By the data to date, there is only one animal in the Galaxy dangerous to man—man himself. So he must supply his own indispensable competition. He has no enemy to help him."
From Time Enough for Love by Robert A. Heinlein
From Time Enough for Love by Robert A. Heinlein
0
#5 Oct 29th, 2009
Found a better way to solve my find external IP problem with Python. It was foolish of me trying to find it through SSH while there were so many other tools out there.
In the end the above code was used. Thanks for all your help anyway.
Python Syntax (Toggle Plain Text)
def getIPAddress(self): """ This function gets your external ip from whatismyop.com this program must be called every 5 minutes not more or else you must have your own server. """ site = urllib.urlopen("http://www.whatismyip.com/automation/n09230945.asp").read() grab = re.findall('\d{2,3}.\d{2,3}.\d{2,3}.\d{2,3}',site) address = grab[0] return address
In the end the above code was used. Thanks for all your help anyway.
"By the data to date, there is only one animal in the Galaxy dangerous to man—man himself. So he must supply his own indispensable competition. He has no enemy to help him."
From Time Enough for Love by Robert A. Heinlein
From Time Enough for Love by Robert A. Heinlein
![]() |
Similar Threads
- How to do Input in Python? (Python)
- Run user given python scripts (Python)
- Screen capture ignoring active window (Python)
- Should I study Python (Python)
- user off website, remain in db (MySQL)
- call a perl script in python having some arguments (Python)
- Making python scripts executables (Python)
- how to get the connected user name in web service (C#)
- Safety of eval function (Python)
Other Threads in the Python Forum
- Previous Thread: Binding DNA
- Next Thread: noob question about strings
| Thread Tools | Search this Thread |
access accessdenied address advice ajax alcatel aliased arax array bash beginner c# c++ calling class code connection csv cturtle data dictionary dns domains dynamic examples file filename function generator gui halp hints http ideas images infosec input internet ip jaunty java keyboard keycontrol law leftmouse limit linux list maze microsoft mysql mysqldb net news newspapers obexftp opensource output path port programming projects py2exe pygame pyopengl python random raw_input remote remoteserver ruby script server software source sprite sqlite ssh string sudokusolver table terminal thread threading time tkinter tricks tutorial ubuntu unicode update urllib urllib2 variable ventrilo web web-scrape whileloop write wxpython






