Add basic output

This commit is contained in:
Marsh232
2022-09-07 13:11:31 +03:00
parent 58bc31adee
commit bf4f4f1a7d
2 changed files with 61 additions and 11 deletions

44
.idea/workspace.xml generated
View File

@@ -4,7 +4,10 @@
<option name="autoReloadType" value="SELECTIVE" />
</component>
<component name="ChangeListManager">
<list default="true" id="56d3644b-12ed-4137-967a-9e3a3c12d93b" name="Changes" comment="" />
<list default="true" id="56d3644b-12ed-4137-967a-9e3a3c12d93b" name="Changes" comment="">
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/main.py" beforeDir="false" afterPath="$PROJECT_DIR$/main.py" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
@@ -17,6 +20,9 @@
<option name="stateVersion" value="1" />
</component>
<component name="ProjectId" id="2EOuFVd4WxG1srr507g2zfLzFMd" />
<component name="ProjectLevelVcsManager" settingsEditedManually="true">
<ConfirmationsSetting value="2" id="Add" />
</component>
<component name="ProjectViewState">
<option name="hideEmptyMiddlePackages" value="true" />
<option name="showLibraryContents" value="true" />
@@ -32,13 +38,16 @@
"node.js.detected.package.tslint": "true",
"node.js.selected.package.eslint": "(autodetect)",
"node.js.selected.package.tslint": "(autodetect)",
"settings.editor.selected.configurable": "preferences.lookFeel"
"settings.editor.selected.configurable": "proofread"
}
}]]></component>
<component name="RunManager">
<configuration name="main" type="PythonConfigurationType" factoryName="Python" nameIsGenerated="true">
<component name="RunManager" selected="Python.main">
<configuration name="main (2)" type="PythonConfigurationType" factoryName="Python" nameIsGenerated="true">
<option name="INTERPRETER_OPTIONS" value="" />
<option name="PARENT_ENVS" value="true" />
<envs>
<env name="PYTHONUNBUFFERED" value="1" />
</envs>
<option name="SDK_HOME" value="C:\Users\truno\AppData\Local\Programs\Python\Python310\python.exe" />
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$" />
<option name="IS_MODULE_SDK" value="false" />
@@ -55,6 +64,29 @@
<option name="INPUT_FILE" value="" />
<method v="2" />
</configuration>
<configuration name="main" type="PythonConfigurationType" factoryName="Python" nameIsGenerated="true">
<module name="Telegram-IP-CALC" />
<option name="INTERPRETER_OPTIONS" value="" />
<option name="PARENT_ENVS" value="true" />
<option name="SDK_HOME" value="C:\Users\truno\AppData\Local\Programs\Python\Python310\python.exe" />
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$" />
<option name="IS_MODULE_SDK" value="false" />
<option name="ADD_CONTENT_ROOTS" value="true" />
<option name="ADD_SOURCE_ROOTS" value="true" />
<EXTENSION ID="PythonCoverageRunConfigurationExtension" runner="coverage.py" />
<option name="SCRIPT_NAME" value="$PROJECT_DIR$/main.py" />
<option name="PARAMETERS" value="" />
<option name="SHOW_COMMAND_LINE" value="false" />
<option name="EMULATE_TERMINAL" value="true" />
<option name="MODULE_MODE" value="false" />
<option name="REDIRECT_INPUT" value="false" />
<option name="INPUT_FILE" value="" />
<method v="2" />
</configuration>
<list>
<item itemvalue="Python.main" />
<item itemvalue="Python.main (2)" />
</list>
</component>
<component name="SpellCheckerSettings" RuntimeDictionaries="0" Folders="0" CustomDictionaries="0" DefaultDictionary="application-level" UseSingleDictionary="true" transferred="true" />
<component name="TaskManager">
@@ -67,6 +99,7 @@
<workItem from="1662478877356" duration="1804000" />
<workItem from="1662485900255" duration="690000" />
<workItem from="1662496666820" duration="3601000" />
<workItem from="1662542574124" duration="2572000" />
</task>
<servers />
</component>
@@ -84,4 +117,7 @@
</map>
</option>
</component>
<component name="com.intellij.coverage.CoverageDataManagerImpl">
<SUITE FILE_PATH="coverage/Telegram_IP_CALC$main.coverage" NAME="main Coverage Results" MODIFIED="1662545082783" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="true" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$" />
</component>
</project>

20
main.py
View File

@@ -1,11 +1,25 @@
import ipaddress
ip = input('Введите ip: ') # Пользователь вводит ip
def main(ip):
list_ip = ip.split('/') # Разделяет вводимый ip на часть с маской, и без
ipv4 = ipaddress.ip_address(list_ip[0])
print('Ваш ip адрес:', ip) # Выводит например "Ваш ip адрес: 192.168.10.128/24"
net = ipaddress.ip_network(ip, strict=False) # В функцию кладётся сетевая часть ip, без хостовой части
print(net)
print(net.netmask)
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
for n_ip in net.hosts():
if str(n_ip) == list_ip[0]:
list_n_ip = str(n_ip).split('.')
print('№ в сети:', list_n_ip[3])
break
if __name__ == '__main__':
addr = input('Введите ip: ') # Пользователь вводит ip
main(addr)