GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — python-code-snippets/localHost-server at main · Mefamex/python-code-snippets

Expand file tree

/

localHost-server

/
Copy path

Directory actions

More options

More options

Directory actions

More options

More options

Latest commit

 

History

History
History
/

localHost-server

/
Copy path

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
.gitignore
.gitignore
 
 
README.md
README.md
 
 
install.bat
install.bat
 
 
main.py
main.py
 
 
run.bat
run.bat
 
 
toExe.bat
toExe.bat
 
 

README.md

Outline

LocalHost Server – Port Taramalı Yerel HTTP Sunucusu

Yerel (localhost / LAN) üzerinde seçilen dizini hızlıca HTTP üzerinden servis eden, bir port aralığını tarayıp ilk boş portu seçebilen, yalnızca Python standart kütüphanesi kullanan hafif araç.

last_modify: 2025-08-13



🚀 Özellikler

  • Port tarama (varsayılan aralık: 8000–8100)
  • Doğrudan port seçimi (-p / --port)
  • Tek port veya aralık (-r 9000-9050 ya da -r 8080)
  • Yerel IP (LAN) tespiti (fallback 127.0.0.1)
  • Windows netstat entegrasyonu ile dolu port listesi
  • Harici bağımlılık yok (sadece standart lib)
  • Basit, okunabilir kod – kolay genişletme



� Gereksinimler

Bileşen Gereksinim
Python 3.8+
OS Windows / Linux / macOS
Bağımlılık Yok

Not: netstat parçası Windows odaklıdır; Linux/macOS için ss veya lsof adaptasyonu ekleyebilirsiniz.



🔧 Kurulum

Bu snippet, python-code-snippets reposunun içindedir. Tüm repoyu indirmeden sadece bu klasörü çekebilirsiniz:

git clone --depth 1 --filter=blob:none --sparse https://github.com/Mefamex/python-code-snippets.git
cd python-code-snippets
git sparse-checkout set localHost-server

Klasörü GitHub'dan indirip localHost-server içine koymanız da yeterlidir.

Ayrıntılar (arşivle indirme, sparse-checkout add/list/disable, alias) için: Git ile Sadece Belirli Alt Klasörleri Klonlama

Ardından:

python main.py

Opsiyonel EXE (PyInstaller):

pip install pyinstaller
pyinstaller --onefile --console main.py



🎯 Kullanım

# Varsayılan aralıkta port ara
python main.py

# Belirli port
python main.py -p 8080

# Özel aralık
python main.py -r 9000-9050

# Tek port dene (aralık gibi yazmadan)
python main.py -r 8081

Tarayıcı erişimi:

http://localhost:<port>
http://<LAN_IP>:<port>



🧭 Argümanlar

Argüman Açıklama Örnek
-p / --port Kesin port -p 8005
-r / --range Aralık veya tek port -r 8100-8200 / -r 8101

Öncelik: --port verilirse aralık yok sayılır.



🧪 Örnek Çıktı

============================== Scanning Ports ==============================
Aralık: 8000-8100
Checking ports : 8000 - 8100
...
Seçilen boş port: 8001
============================== Starting HTTP Server ==============================
İstenen port: 8001
Çalışma dizini  : D:\\localHost-server
Erişim adresleri:
  http://localhost:8001  |  http://192.168.1.34:8001
(Ctrl+C ile durdur)



🛡️ Güvenlik Notları

  • Kimlik doğrulama yok; aynı ağdaki herkes dosyaları görebilir.
  • Hassas dizinlerde çalıştırmayın (örn. bütün C:\ kökü).
  • İnternete port yönlendirmesi (NAT) yapmayın.



⚙️ İç Yapı

İşlev Amaç
find_available_port Aralıkta bind denemesi ile ilk boş port
is_port_in_use bind başarısız ise port dolu varsayımı
get_local_ip Routing tablosu + hostname fallback
run_server socketserver.TCPServer ile servis



❗ Yaygın Sorunlar

Belirti Neden Çözüm
getaddrinfo failed Hatalı host tuple Host boş string olsun: ("", port)
Port dolu gözüküyor Firewall / başka servis / izin Farklı aralık, yönetici mod veya izin ayarı
LAN IP 127.0.0.1 Yönlendirme yok Aynı makine için sorun değil



🔍 Genişletme Fikirleri

  • IPv6 / ThreadingTCPServer
  • Çoklu sürücü map (C, D) -> özel handler
  • Basit Basic-Auth ekleme
  • Renkli terminal (colorama) desteği



Proje Bağlantıları

  • MEFAMEX | Python Code Snippets
  • Mefamex.com/projects




You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.