Отрефакторил, убрал конфиг в игнор

This commit is contained in:
Maxim Khomutov 2022-09-12 14:01:08 +03:00
parent fd7e865b1a
commit 66e18240a0
9 changed files with 91 additions and 48 deletions

42
.gitignore vendored Normal file
View File

@ -0,0 +1,42 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
# C extensions
*.so
# Distribution / packaging
bin/
build/
develop-eggs/
dist/
eggs/
lib/
lib64/
parts/
sdist/
var/
*.egg-info/
.installed.cfg
*.egg
# Installer logs
pip-log.txt
pip-delete-this-directory.txt
# Unit test / coverage reports
.tox/
.coverage
.cache
nosetests.xml
coverage.xml
# Translations
*.mo
# Mr Developer
.mr.developer.cfg
.project
.pydevproject
# Rope
.ropeproject
# Django stuff:
*.log
*.pot
# Sphinx documentation
docs/_build/
config.json

View File

@ -1,8 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/venv" />
</content>
<orderEntry type="jdk" jdkName="Python 3.10 (Telegram-IP-CALC)" jdkType="Python SDK" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

6
.idea/copyright/SantaSpeen.xml generated Normal file
View File

@ -0,0 +1,6 @@
<component name="CopyrightManager">
<copyright>
<option name="notice" value="Project: &amp;#36;project.name&#10;Filename: &amp;#36;file.fileName&#10;Create Date: &amp;#36;today&#10;SantaSpeen Copyright (c) &amp;#36;today.year" />
<option name="myName" value="SantaSpeen" />
</copyright>
</component>

2
.idea/misc.xml generated
View File

@ -1,4 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.10" project-jdk-type="Python SDK" />
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.10 (Telegram-IP-CALC)" project-jdk-type="Python SDK" />
</project>

47
.idea/workspace.xml generated
View File

@ -5,8 +5,14 @@
</component>
<component name="ChangeListManager">
<list default="true" id="56d3644b-12ed-4137-967a-9e3a3c12d93b" name="Changes" comment="Начал добовлять в телеграм 2">
<change afterPath="$PROJECT_DIR$/.gitignore" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/copyright/SantaSpeen.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/Telegram-IP-CALC.iml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/Telegram-IP-CALC.iml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/misc.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/misc.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/config.py" beforeDir="false" afterPath="$PROJECT_DIR$/config.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/LICENSE" beforeDir="false" afterPath="$PROJECT_DIR$/LICENSE" afterDir="false" />
<change beforePath="$PROJECT_DIR$/README.md" beforeDir="false" afterPath="$PROJECT_DIR$/README.md" afterDir="false" />
<change beforePath="$PROJECT_DIR$/config.py" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/main.py" beforeDir="false" afterPath="$PROJECT_DIR$/main.py" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
@ -35,20 +41,21 @@
<option name="hideEmptyMiddlePackages" value="true" />
<option name="showLibraryContents" value="true" />
</component>
<component name="PropertiesComponent">{
&quot;keyToString&quot;: {
&quot;ASKED_SHARE_PROJECT_CONFIGURATION_FILES&quot;: &quot;true&quot;,
&quot;RunOnceActivity.OpenProjectViewOnStart&quot;: &quot;true&quot;,
&quot;RunOnceActivity.ShowReadmeOnStart&quot;: &quot;true&quot;,
&quot;WebServerToolWindowFactoryState&quot;: &quot;false&quot;,
&quot;last_opened_file_path&quot;: &quot;C:/Users/truno/Documents/GitHub/Telegram-IP-CALC&quot;,
&quot;node.js.detected.package.eslint&quot;: &quot;true&quot;,
&quot;node.js.detected.package.tslint&quot;: &quot;true&quot;,
&quot;node.js.selected.package.eslint&quot;: &quot;(autodetect)&quot;,
&quot;node.js.selected.package.tslint&quot;: &quot;(autodetect)&quot;,
&quot;settings.editor.selected.configurable&quot;: &quot;proofread&quot;
<component name="PropertiesComponent"><![CDATA[{
"keyToString": {
"ASKED_SHARE_PROJECT_CONFIGURATION_FILES": "true",
"RunOnceActivity.OpenProjectViewOnStart": "true",
"RunOnceActivity.ShowReadmeOnStart": "true",
"SHARE_PROJECT_CONFIGURATION_FILES": "true",
"WebServerToolWindowFactoryState": "false",
"last_opened_file_path": "C:/Users/truno/Documents/GitHub/Telegram-IP-CALC",
"node.js.detected.package.eslint": "true",
"node.js.detected.package.tslint": "true",
"node.js.selected.package.eslint": "(autodetect)",
"node.js.selected.package.tslint": "(autodetect)",
"settings.editor.selected.configurable": "com.jetbrains.python.configuration.PyActiveSdkModuleConfigurable"
}
}</component>
}]]></component>
<component name="RunManager" selected="Python.main">
<configuration name="main (2)" type="PythonConfigurationType" factoryName="Python" nameIsGenerated="true">
<option name="INTERPRETER_OPTIONS" value="" />
@ -115,6 +122,7 @@
<workItem from="1662886058001" duration="5482000" />
<workItem from="1662931348193" duration="2714000" />
<workItem from="1662934797487" duration="309000" />
<workItem from="1662979769296" duration="616000" />
</task>
<task id="LOCAL-00001" summary="Add basic output">
<created>1662545492088</created>
@ -184,17 +192,6 @@
<MESSAGE value="Начал добовлять в телеграм 2" />
<option name="LAST_COMMIT_MESSAGE" value="Начал добовлять в телеграм 2" />
</component>
<component name="XDebuggerManager">
<breakpoint-manager>
<breakpoints>
<line-breakpoint enabled="true" suspend="THREAD" type="python-line">
<url>file://$PROJECT_DIR$/main.py</url>
<line>52</line>
<option name="timeStamp" value="1" />
</line-breakpoint>
</breakpoints>
</breakpoint-manager>
</component>
<component name="com.intellij.coverage.CoverageDataManagerImpl">
<SUITE FILE_PATH="coverage/Telegram_IP_CALC$main.coverage" NAME="main Coverage Results" MODIFIED="1662935064255" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="true" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$" />
</component>

View File

@ -1,6 +1,7 @@
MIT License
Copyright (c) 2022 Marsh232
Copyright (c) 2022 SantaSpeen
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal

View File

@ -1 +1,4 @@
# Telegram-IP-CALC
# Telegram-IP-CALC
Калькулятор для вычисления IP сетей. \
Бот в телеграм:

View File

@ -1,2 +0,0 @@
TOKEN = '5631324818:AAEcOp7ZPzeSQReLk7rwnAT89n76ld05Jko' # bot token

28
main.py
View File

@ -1,28 +1,22 @@
import config
import telebot
import ipaddress
bot = telebot.TeleBot(config.TOKEN)
@bot.message_handler(commands=['start'])
def start(message):
bot.send_message(message.chat.id, 'Привет')
def main(ip):
list_ip = ip.split('/') # Разделяет вводимый ip на часть с маской, и без
print('Ваш ip адрес:', ip) # Выводит например "Ваш ip адрес: 192.168.10.128/24"
list_ip = ip.split('/') # Разделяет вводимый ip на часть с маской, и без
print('Ваш ip адрес:', ip) # Выводит например "Ваш ip адрес: 192.168.10.128/24"
net = ipaddress.ip_network(ip, strict=False) # В функцию кладётся сетевая часть ip, без хостовой части
print('Маска:', net.netmask, '=', list_ip[1], '\n') # Выводит маску
print('Network:', net) # Выводит сеть
print('Broadcast:', net.broadcast_address) # Выводит broad
net = ipaddress.ip_network(ip, strict=False) # В функцию кладётся сетевая часть ip, без хостовой части
print('Маска:', net.netmask, '=', list_ip[1], '\n') # Выводит маску
print('Network:', net) # Выводит сеть
print('Broadcast:', net.broadcast_address) # Выводит broad
print('HostMin:', net[1])
print('HostMax:', net[-2])
print('Hosts:', len(list(net.hosts()))) # Выводит кол-во хостовых ip
print('Hosts:', len(list(net.hosts()))) # Выводит кол-во хостовых ip
count = 0
for n_ip in net.hosts():
count += 1
if str(n_ip) == list_ip[0]:
print('№ в сети:', count) # Выводит какой ip по счёту в сети
print('№ в сети:', count) # Выводит какой ip по счёту в сети
break
@ -45,9 +39,9 @@ def subnets(ip, prefix):
if __name__ == '__main__':
bot.polling(none_stop=True)
addr = input('Введите ip: ') # Пользователь вводит ip
addr = input('Введите ip: ') # Пользователь вводит ip
main(addr)
exit(0)
# Тут должна быть кнопка типа "Подсети"
new_prefix = input('\nВведите префикс: ')
subnets(addr, new_prefix)
subnets(addr, new_prefix)