Skip to content

Commit

Permalink
Log host ip
Browse files Browse the repository at this point in the history
  • Loading branch information
GioF71 committed Dec 11, 2024
1 parent e1515fa commit 7aeb8cd
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ Start the container with the following:

DATE|DESCRIPTION
:---|:---
2024-12-11|Log host ip
2024-12-10|Add debug logging, to be refined
2024-11-29|Improved general reliability and management of duration
2024-11-28|Fixed parsing of duration
Expand Down
17 changes: 17 additions & 0 deletions upnp_scrobbler/scrobbler.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import os
import datetime
import pylast
import socket

from typing import Optional, Sequence, Union

Expand Down Expand Up @@ -460,7 +461,23 @@ async def async_main() -> None:
service_names=service)


def get_ip():
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.settimeout(0)
try:
# doesn't even have to be reachable
s.connect(('8.8.8.8', 1))
IP = s.getsockname()[0]
except Exception:
IP = '127.0.0.1'
finally:
s.close()
return IP


def main() -> None:
host_ip: str = get_ip()
print(f"Running on [{host_ip}]")
"""Set up async loop and run the main program."""
loop = asyncio.get_event_loop()
try:
Expand Down

0 comments on commit 7aeb8cd

Please sign in to comment.