Skip to content

Instantly share code, notes, and snippets.

@todd-dsm
Forked from nZac/app.py
Created March 20, 2017 21:36
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 todd-dsm/27013df24903200967d07b84b9779041 to your computer and use it in GitHub Desktop.
Save todd-dsm/27013df24903200967d07b84b9779041 to your computer and use it in GitHub Desktop.
import flask
import socket
import fcntl
import struct
app = flask.Flask(__name__)
# http://stackoverflow.com/questions/24196932/how-can-i-get-the-ip-address-of-eth0-in-python
def get_ip_address(ifname):
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
return socket.inet_ntoa(fcntl.ioctl(
s.fileno(),
0x8915, # SIOCGIFADDR
struct.pack('256s', ifname[:15])
)[20:24])
@app.route('/')
def ip():
return get_ip_address('eth0')
if __name__ == '__main__':
app.run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment