WorkTools.git

WorkTools

~
git clone https://github.com/debuman/WorkTools.git
commit 69a9877652b2c80873173891e61ee38d4eb031b4
Author: saladball <38815353+saladball@users.noreply.github.com>
Date: Sat, 13 May 2023 21:26:00 +0900

Initial commit

Diffstat:
A.gitattributes | 2++
AGeoLite2-Country.mmdb | 0binary
ALICENSE | 21+++++++++++++++++++++
AREADME.md | 2++
Aapp.py | 63+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Atemplates/ascii_to_char.html | 73+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Atemplates/index.html | 77+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
7 files changed, 238 insertion(+), 0 deletion(-)

diff --git a/.gitattributes b/.gitattributes
@@ -0,0 +1,2 @@
+# Auto detect text files and perform LF normalization
+* text=auto
diff --git a/GeoLite2-Country.mmdb b/GeoLite2-Country.mmdb
Binary files differ.
diff --git a/LICENSE b/LICENSE
@@ -0,0 +1,21 @@
+MIT License
+
+Copyright (c) 2023 saladball
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
diff --git a/README.md b/README.md
@@ -0,0 +1,2 @@
+# SecurityTools
+ 
diff --git a/app.py b/app.py
@@ -0,0 +1,63 @@
+import geoip2.database
+import socket
+import re
+from flask import Flask, render_template, request
+
+app = Flask(__name__)
+
+# GeoLite2 데이터베이스 파일의 경로를 지정합니다.
+reader = geoip2.database.Reader('GeoLite2-Country.mmdb')
+
+def get_ip_address(input_value):
+    try:
+        if not input_value.replace(".", "").isnumeric():  # If it's a domain name
+            ip_address = socket.gethostbyname(input_value)
+            return ip_address
+        else:  # If it's an IP address
+            return input_value
+    except socket.gaierror:
+        return None
+
+@app.route('/', methods=['GET', 'POST'])
+def index():
+    ip_data = []
+
+    if request.method == 'POST':
+        input_list = request.form['ip_list'].splitlines()
+
+        for input_value in input_list:
+            ip_address = get_ip_address(input_value)
+            if ip_address is None:
+                ip_data.append({
+                    'ip': 'Invalid IP or Domain',
+                    'country': 'Invalid IP or Domain'
+                })
+            else:
+                try:
+                    response = reader.country(ip_address)
+                    ip_data.append({
+                        'ip': input_value,
+                        'country': response.country.name
+                    })
+                except:
+                    ip_data.append({
+                        'ip': input_value,
+                        'country': 'Invalid IP'
+                    })
+
+    return render_template('index.html', ip_data=ip_data)
+
+@app.route('/ascii_to_char', methods=['GET', 'POST'])
+def ascii_to_char():
+    characters = ''
+    if request.method == 'POST':
+        ascii_string = request.form.get('ascii_string')
+        ascii_codes = re.findall(r'\d+', ascii_string)
+        for ascii_code in ascii_codes:
+            ascii_code = int(ascii_code)
+            if ascii_code >= 0 and ascii_code <= 127:
+                characters += chr(ascii_code)
+    return render_template('ascii_to_char.html', characters=characters)
+
+if __name__ == '__main__':
+    app.run()
diff --git a/templates/ascii_to_char.html b/templates/ascii_to_char.html
@@ -0,0 +1,73 @@
+<!DOCTYPE html>
+<html lang="en">
+  <head>
+    <!-- Required meta tags -->
+    <meta charset="utf-8" />
+    <meta name="viewport" content="width=device-width, initial-scale=1" />
+
+    <!-- Bootstrap CSS -->
+    <link
+      href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css"
+      rel="stylesheet"
+    />
+
+    <title>ASCII Code Converter</title>
+  </head>
+  <body>
+    <nav class="navbar navbar-expand-lg navbar-light bg-light">
+      <a class="navbar-brand" href="#">Navigation</a>
+      <button
+        class="navbar-toggler"
+        type="button"
+        data-toggle="collapse"
+        data-target="#navbarNav"
+        aria-controls="navbarNav"
+        aria-expanded="false"
+        aria-label="Toggle navigation"
+      >
+        <span class="navbar-toggler-icon"></span>
+      </button>
+      <div class="collapse navbar-collapse" id="navbarNav">
+        <ul class="navbar-nav">
+          <li class="nav-item active">
+            <a class="nav-link" href="/">IP & Domain Country Finder</a>
+          </li>
+          <li class="nav-item">
+            <a class="nav-link" href="/ascii_to_char">ASCII Code Converter</a>
+          </li>
+        </ul>
+      </div>
+    </nav>
+
+    <div class="container">
+      <h1 class="my-4">ASCII Code Converter</h1>
+
+      <form method="POST">
+        <div class="form-group">
+          <label for="asciiString"
+            >Enter ASCII Strings (e.g., Char(65) Char(66))</label
+          >
+          <input
+            type="text"
+            class="form-control"
+            id="asciiString"
+            name="ascii_string"
+            required
+          />
+        </div>
+        <button type="submit" class="btn btn-primary">Convert</button>
+      </form>
+
+      {% if characters %}
+      <div class="alert alert-success mt-4" role="alert">
+        Corresponding Characters: {{ characters }}
+      </div>
+      {% endif %}
+    </div>
+
+    <!-- Optional JavaScript; choose one of the two! -->
+    <!-- Option 1: jQuery and Bootstrap Bundle (includes Popper) -->
+    <script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"></script>
+    <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.bundle.min.js"></script>
+  </body>
+</html>
diff --git a/templates/index.html b/templates/index.html
@@ -0,0 +1,77 @@
+<!DOCTYPE html>
+<html lang="en">
+  <head>
+    <meta charset="utf-8" />
+    <meta name="viewport" content="width=device-width, initial-scale=1" />
+    <title>IP to Country</title>
+    <!-- 부트스트랩 CSS 추가 -->
+    <link
+      href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css"
+      rel="stylesheet"
+    />
+  </head>
+  <body>
+    <nav class="navbar navbar-expand-lg navbar-light bg-light">
+      <a class="navbar-brand" href="#">Navigation</a>
+      <button
+        class="navbar-toggler"
+        type="button"
+        data-toggle="collapse"
+        data-target="#navbarNav"
+        aria-controls="navbarNav"
+        aria-expanded="false"
+        aria-label="Toggle navigation"
+      >
+        <span class="navbar-toggler-icon"></span>
+      </button>
+      <div class="collapse navbar-collapse" id="navbarNav">
+        <ul class="navbar-nav">
+          <li class="nav-item active">
+            <a class="nav-link" href="/">IP & Domain Country Finder</a>
+          </li>
+          <li class="nav-item">
+            <a class="nav-link" href="/ascii_to_char">ASCII Code Converter</a>
+          </li>
+        </ul>
+      </div>
+    </nav>
+
+    <div class="container">
+      <h1 class="my-3">IP to Country</h1>
+      <form method="post">
+        <div class="mb-3">
+          <label for="ip_list" class="form-label">IP List:</label>
+          <textarea
+            class="form-control"
+            name="ip_list"
+            id="ip_list"
+            rows="10"
+          ></textarea>
+        </div>
+        <input type="submit" class="btn btn-primary" value="Submit" />
+      </form>
+      {% if ip_data %}
+      <table class="table table-striped table-hover my-3">
+        <thead>
+          <tr>
+            <th scope="col">IP Address</th>
+            <th scope="col">Country</th>
+          </tr>
+        </thead>
+        <tbody>
+          {% for data in ip_data %}
+          <tr>
+            <td>{{ data.ip }}</td>
+            <td>{{ data.country }}</td>
+          </tr>
+          {% endfor %}
+        </tbody>
+      </table>
+      {% endif %}
+    </div>
+    <!-- 부트스트랩 및 Popper.js 추가 -->
+    <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
+    <script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.11.6/dist/umd/popper.min.js"></script>
+    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/js/bootstrap.min.js"></script>
+  </body>
+</html>