-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c32063e
commit 6c05c80
Showing
6 changed files
with
186 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
""" | ||
Example: Asynchronous Telnet Connection with Default Timeout | ||
This example demonstrates an asynchronous Telnet connection to 'example.com' using the asyncio_telnet library. | ||
The default timeout for the connection is set to 30 seconds. | ||
Usage: | ||
- Install the asyncio_telnet library: pip install asyncio-telnet | ||
- Run the script. | ||
Note: Make sure to replace 'example.com' with the actual hostname or IP address. | ||
""" | ||
|
||
import asyncio | ||
from asyncio_telnet import Telnet | ||
|
||
async def main(): | ||
tn = Telnet() | ||
await tn.open('example.com') | ||
await tn.write(b'Vladimir\r\n') | ||
response = await tn.read_until_eof() | ||
await tn.close() | ||
return response | ||
|
||
if __name__ == '__main__': | ||
result = asyncio.run(main()) | ||
print(result) | ||
|
||
|
||
# Example of successful execution: | ||
# b'\n***************** User Access Login ********************\r\n\r\nUser:' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
""" | ||
Example: Asynchronous Telnet Connection with Custom Timeout | ||
This example demonstrates an asynchronous Telnet connection to 'example.com' using the asyncio_telnet library. | ||
The connection has a custom timeout of 5 seconds. | ||
Usage: | ||
- Install the asyncio_telnet library: pip install asyncio-telnet | ||
- Run the script. | ||
Note: Make sure to replace 'example.com' with the actual hostname or IP address. | ||
""" | ||
|
||
import asyncio | ||
from asyncio_telnet import Telnet | ||
|
||
async def main(): | ||
tn = Telnet(timeout=5) | ||
try: | ||
await tn.open('example.com') | ||
response = await tn.read_until_eof() | ||
await tn.close() | ||
return response | ||
except ValueError as e: | ||
print(f"Example of a timeout occurrence: {e}") | ||
|
||
if __name__ == '__main__': | ||
asyncio.run(main()) | ||
|
||
|
||
# Example response: | ||
# Example of a timeout occurrence: Timeout connecting to example.com:23 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
""" | ||
Example: Asynchronous Telnet Connection with Write Operation | ||
This example demonstrates an asynchronous Telnet connection to 'example.com' using the asyncio_telnet library. | ||
The script opens a connection, writes 'Vladimir\r\n' to the Telnet server, and then reads the response. | ||
Usage: | ||
- Install the asyncio_telnet library: pip install asyncio-telnet | ||
- Run the script. | ||
Note: Make sure to replace 'example.com' with the actual hostname or IP address. | ||
""" | ||
|
||
import asyncio | ||
from asyncio_telnet import Telnet | ||
|
||
async def main(): | ||
tn = Telnet() | ||
await tn.open('example.com') | ||
await tn.write(b'Vladimir\r\n') | ||
response = await tn.read_until_eof() | ||
await tn.close() | ||
return response | ||
|
||
if __name__ == '__main__': | ||
result = asyncio.run(main()) | ||
print(result) | ||
|
||
|
||
# Example of successful execution: | ||
# b'\n***************** User Access Login ********************\r\n\r\nUser:Vladimir\r\nPassword:' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
""" | ||
Example: Synchronous Telnet Connection | ||
This example demonstrates a synchronous Telnet connection to 'example.com' using the asyncio_telnet library. | ||
By specifying sync_mode=True, a wrapper for calling asynchronous methods synchronously is activated internally. | ||
Usage: | ||
- Install the asyncio_telnet library: pip install asyncio-telnet | ||
- Run the script. | ||
Note: Make sure to replace 'example.com' with the actual hostname or IP address. | ||
""" | ||
|
||
from asyncio_telnet import Telnet | ||
|
||
def main(): | ||
tn = Telnet(sync_mode=True) | ||
tn.open('example.com') | ||
response = tn.read_until_eof() | ||
tn.close() | ||
return response | ||
|
||
if __name__ == '__main__': | ||
result = main() | ||
print(result) | ||
|
||
|
||
# Example of successful execution: | ||
# b'\n***************** User Access Login ********************\r\n\r\nUser:' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
""" | ||
Example: Synchronous Telnet Connection with Timeout | ||
This example demonstrates a synchronous Telnet connection to 'example.com' using the asyncio_telnet library. | ||
By specifying sync_mode=True and timeout=5, a wrapper for calling asynchronous methods synchronously is activated. | ||
The script opens a connection, reads the response, and closes the connection. | ||
Usage: | ||
- Install the asyncio_telnet library: pip install asyncio-telnet | ||
- Run the script. | ||
Note: Make sure to replace 'example.com' with the actual hostname or IP address. | ||
""" | ||
|
||
from asyncio_telnet import Telnet | ||
|
||
def main(): | ||
tn = Telnet(sync_mode=True, timeout=5) | ||
try: | ||
tn.open('example.com') | ||
response = tn.read_until_eof() | ||
tn.close() | ||
return response | ||
except ValueError as e: | ||
print(f"Example of a timeout occurrence: {e}") | ||
|
||
|
||
if __name__ == '__main__': | ||
result = main() | ||
print(result) | ||
|
||
|
||
# Example response: | ||
# Example of a timeout occurrence: Timeout connecting to example.com:23 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
""" | ||
Example: Synchronous Telnet Connection with Write Operation | ||
This example demonstrates a synchronous Telnet connection to 'example.com' using the asyncio_telnet library. | ||
By specifying sync_mode=True, a wrapper for calling asynchronous methods synchronously is activated internally. | ||
Usage: | ||
- Install the asyncio_telnet library: pip install asyncio-telnet | ||
- Run the script. | ||
Note: Make sure to replace 'example.com' with the actual IP address. | ||
""" | ||
|
||
from asyncio_telnet import Telnet | ||
|
||
def main(): | ||
tn = Telnet(sync_mode=True) | ||
tn.open('example.com') | ||
tn.write(b'Vladimir\r\n') | ||
response = tn.read_until_eof() | ||
tn.close() | ||
return response | ||
|
||
if __name__ == '__main__': | ||
result = main() | ||
print(result) | ||
|
||
# Example of successful execution: | ||
# b'\n***************** User Access Login ********************\r\n\r\nUser:Vladimir\r\nPassword:' |