11 Commits
Author SHA1 Message Date
iamdoubz 3c21f648de Add verbage in logging steps 2025-05-21 15:41:28 -05:00
iamdoubz 424982cd3c Add external VERSION file 2025-05-21 15:38:31 -05:00
iamdoubz 6584c1b85e Add files to display version information in executable 2025-05-21 14:58:38 -05:00
iamdoubz af2e98e091 Add more items to ignore 2025-05-21 14:57:25 -05:00
iamdoubz c698eb6394 Add gitignore file for security reasons 2025-05-21 14:38:07 -05:00
iamdoubz 1ee7344df6 dotenv fixes 2025-05-21 14:33:21 -05:00
iamdoubz 9317472071 Merge pull request 'Add dotenv for python' (#2) from dev into main
Reviewed-on: #2
2025-05-21 14:03:24 -05:00
iamdoubz 3e4cf727a6 Add more requirements for python 2025-05-21 14:02:36 -05:00
iamdoubz e3af068661 Add .env steps to python section 2025-05-21 13:59:41 -05:00
iamdoubz 3c802467bc Add env example 2025-05-21 13:53:16 -05:00
iamdoubz 7ff000dc6f Read HOST and PORT from .env file 2025-05-21 13:51:41 -05:00
8 changed files with 121 additions and 14 deletions
+6
View File
@@ -0,0 +1,6 @@
__pycache__/
.env
*.log
app.ico
build/
dist/
+8 -6
View File
@@ -8,7 +8,7 @@ A simple program that integrates with Windows Services to retrieve the hostname
- At least python3.10 or higher (may work on lower versions but untested)
- python and pip are in your environmental variables (python --version)
- `pip install pywin32`
- `pip install pywin32 python-dotenv`
### Go
@@ -20,9 +20,11 @@ A simple program that integrates with Windows Services to retrieve the hostname
### Python
1. Download `hostname-service.py` file
2. Open terminal as admin
3. `python hostname_service.py run`
1. Download `hostname-service.py` and `env.txt` files
2. Copy `env.txt` to `.env`
3. Edit `.env` file to match your requirements
4. Open terminal as admin
5. `python hostname_service.py run`
### Go
@@ -56,11 +58,11 @@ Use `python hostname_service.py` and one of the following option names.
### Go
Use `./hostname_service.exe` and one of the following option names.
Use `go run hostname_service.go` and one of the following option names.
| Option Name | Description |
| :---: | ---: |
| | Start the server in standalone mode |
| run | Start the server in standalone mode |
| install | Create a Windows Service entry |
| start | Start the Windows service |
| stop | Stop the Windows service |
+1
View File
@@ -0,0 +1 @@
2025.5.6.0
+2
View File
@@ -0,0 +1,2 @@
HOST=127.0.0.1
PORT=8999
+44
View File
@@ -0,0 +1,44 @@
# UTF-8
#
# For more details about fixed file info 'ffi' see:
# http://msdn.microsoft.com/en-us/library/ms646997.aspx
VSVersionInfo(
ffi=FixedFileInfo(
# filevers and prodvers should be always a tuple with four items: (1, 2, 3, 4)
# Set not needed items to zero 0. Must always contain 4 elements.
filevers=(2025,5,6,0),
prodvers=(2025,5,6,0),
# Contains a bitmask that specifies the valid bits 'flags'r
mask=0x3f,
# Contains a bitmask that specifies the Boolean attributes of the file.
flags=0x0,
# The operating system for which this file was designed.
# 0x4 - NT and there is no need to change it.
OS=0x40004,
# The general type of file.
# 0x1 - the file is an application.
fileType=0x1,
# The function of the file.
# 0x0 - the function is not defined for this fileType
subtype=0x0,
# Creation date and time stamp.
date=(0, 0)
),
kids=[
StringFileInfo(
[
StringTable(
u'040904B0',
[StringStruct(u'CompanyName', u''),
StringStruct(u'FileDescription', u'HTTP service that resolves hostnames from IPs (POST only)'),
StringStruct(u'FileVersion', u'2025.5.6.0'),
StringStruct(u'InternalName', u'HostnameHTTPServicePython'),
StringStruct(u'LegalCopyright', u'© iamdoubz'),
StringStruct(u'OriginalFilename', u'hostname_service.exe'),
StringStruct(u'ProductName', u'HostnameHTTPServicePython'),
StringStruct(u'ProductVersion', u'2025.5.6.0')])
]),
VarFileInfo([VarStruct(u'Translation', [1033, 1200])])
]
)
+14 -8
View File
@@ -1,4 +1,6 @@
from http.server import BaseHTTPRequestHandler, HTTPServer
from dotenv import load_dotenv
from pathlib import Path
import socket
import json
import threading
@@ -10,9 +12,13 @@ import servicemanager
import os
import sys
HOST = '0.0.0.0'
PORT = 8999
LOG_FILE = os.path.join(os.path.dirname(__file__), 'hostname_service.log')
# Load environment variables from .env file
dotenv_p = Path('./.env')
load_dotenv(dotenv_path=dotenv_p)
HOST = os.getenv("HOST", "0.0.0.0")
PORT = int(os.getenv("PORT", 8999))
LOG_FILE = os.getenv("LOG_FILE", os.path.join(os.path.dirname(__file__), 'hostname_service.log'))
logging.basicConfig(
filename=LOG_FILE,
@@ -69,9 +75,9 @@ class RequestHandler(BaseHTTPRequestHandler):
return # Silence default stdout logging
class HostnameService(win32serviceutil.ServiceFramework):
_svc_name_ = "HostnameHTTPService"
_svc_name_ = "HostnameHTTPServicePython"
_svc_display_name_ = "Hostname HTTP Resolver Service"
_svc_description_ = "HTTP service that resolves hostnames from IPs on port 8999 (POST only)."
_svc_description_ = "HTTP service that resolves hostnames from IPs (POST only)."
def __init__(self, args):
super().__init__(args)
@@ -101,7 +107,7 @@ class HostnameService(win32serviceutil.ServiceFramework):
def run_server(self):
try:
self.httpd = HTTPServer((HOST, PORT), RequestHandler)
logging.info(f"HTTP server started on port {PORT}")
logging.info(f"HTTP server started on port {PORT} for host {HOST}")
self.httpd.serve_forever()
except Exception as e:
logging.exception("Server failed: %s", str(e))
@@ -113,9 +119,9 @@ if __name__ == '__main__':
else:
if sys.argv[1] == "run":
# Allow running standalone (not as service)
logging.info("Running in standalone HTTP mode.")
logging.info("Running in standalone HTTP mode on port {PORT} for host {HOST}")
httpd = HTTPServer((HOST, PORT), RequestHandler)
print(f"Listening on port {PORT}...")
print(f"Listening on port {PORT} for host {HOST}...")
try:
httpd.serve_forever()
except KeyboardInterrupt:
+40
View File
@@ -0,0 +1,40 @@
# -*- mode: python ; coding: utf-8 -*-
a = Analysis(
['hostname_service.py'],
pathex=[],
binaries=[],
datas=[],
hiddenimports=['win32timezone'],
hookspath=[],
hooksconfig={},
runtime_hooks=[],
excludes=[],
noarchive=False,
optimize=0,
)
pyz = PYZ(a.pure)
exe = EXE(
pyz,
a.scripts,
a.binaries,
a.datas,
[],
name='hostname_service',
debug=False,
bootloader_ignore_signals=False,
strip=False,
upx=True,
upx_exclude=[],
runtime_tmpdir=None,
console=True,
disable_windowed_traceback=False,
argv_emulation=False,
target_arch=None,
codesign_identity=None,
entitlements_file=None,
version='file_version_info.txt',
icon=['app.ico'],
)
+6
View File
@@ -0,0 +1,6 @@
Version: VERSION
FileDescription: HTTP service that resolves hostnames from IPs (POST only)
InternalName: HostnameHTTPServicePython
LegalCopyright: © iamdoubz
OriginalFilename: hostname_service.exe
ProductName: HostnameHTTPServicePython