Ping the Web avatar
Ping the Web

Pricing

Pay per usage

Go to Store
Ping the Web

Ping the Web

Developed by

Canadesk Support

Canadesk Support

Maintained by Community

A simple endpoint to ping servers (OK/KO).

0.0 (0)

Pricing

Pay per usage

1

Total users

5

Monthly users

2

Runs succeeded

>99%

Last modified

2 years ago

.actor/Dockerfile

# First, specify the base Docker image.
# You can see the Docker images from Apify at https://hub.docker.com/r/apify/.
# You can also use any other image from Docker Hub.
FROM apify/actor-python:3.11
# Second, copy just requirements.txt into the actor image,
# since it should be the only file that affects the dependency install in the next step,
# in order to speed up the build
COPY requirements.txt ./
# Install the packages specified in requirements.txt,
# Print the installed Python version, pip version
# and all installed packages with their versions for debugging
RUN echo "Python version:" \
&& python --version \
&& echo "Pip version:" \
&& pip --version \
&& echo "Installing dependencies:" \
&& pip install -r requirements.txt \
&& echo "All installed Python packages:" \
&& pip freeze
# Next, copy the remaining files and directories with the source code.
# Since we do this after installing the dependencies, quick build will be really fast
# for most source file changes.
COPY . ./
# Specify how to launch the source code of your actor.
# By default, the "python3 -m src" command is run
CMD ["python3", "-m", "src"]

.actor/actor.json

{
"actorSpecification": 1,
"name": "ping-the-web",
"title": "Ping the Web",
"description": "Ping the Web.",
"version": "1.0",
"meta": {
"templateId": "python-beautifulsoup"
},
"input": "./input_schema.json",
"dockerfile": "./Dockerfile"
}

.actor/input_schema.json

{
"title": "Ping the Web",
"type": "object",
"schemaVersion": 1,
"properties": {
"url": {
"title": "URL",
"type": "string",
"description": "The website you want to test. Do not include the protocol.",
"prefill": "google.com",
"editor": "textfield"
}
},
"required": ["url"]
}

src/main.py

1from apify import Actor
2from icmplib import ping
3
4def host_up(hostname:str):
5 host = ping(hostname, count=5, interval=0.2)
6 print(host)
7 return host.is_alive
8
9async def main():
10 async with Actor:
11 actor_input = await Actor.get_input() or {}
12 # Structure of input is defined in .actor/input_schema.json
13 host = actor_input.get('url')
14 response = "KO"
15
16 try:
17 if host_up(host):
18 response = "OK"
19 print(f"{host} - Connection successful!")
20 except:
21 print(f"{host} - Connection failed...")
22 response = "KO"
23
24 await Actor.push_data([
25 {
26 'result': response
27 },
28 ])

.dockerignore

# configurations
.idea
# crawlee and apify storage folders
apify_storage
crawlee_storage
storage
# installed files
.venv
# git folder
.git

.editorconfig

root = true
[*]
indent_style = space
indent_size = 4
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
end_of_line = lf

.gitignore

# This file tells Git which files shouldn't be added to source control
.idea
.DS_Store
apify_storage
storage
.venv/
.env/
__pypackages__
dist/
build/
*.egg-info/
*.egg
__pycache__
.mypy_cache
.dmypy.json
dmypy.json
.pytest_cache
.scrapy
*.log

requirements.txt

1# Add your dependencies here.
2# See https://pip.pypa.io/en/latest/reference/requirements-file-format/
3# for how to format them
4apify ~= 1.1.1
5icmplib