How to create your own API or access API file which was a store in another PC without any access with the help of network connectivity and IP address ⇾

Vishugoyal
4 min readApr 22, 2021

This whole blog helps you give info. About the API’s and CGI’s in web server and web app in every detail :

API stands for an Application programming interface
CGI stands for Commonly gateway interface

Note :
* we can not access the application(software) file with remote access.
* we can not access the application (software) file with local access.
* we can not access the application (software) file with login and password.

First, you have network connectivity with other PC to access the code file.
Second, you know about the IP address of the other PC to ping with each other.

How to know the IP address of the OS.
By running the below cmd...

Now open the folder (cd /var/www/cgi-bin/) by running this cmd.
Why we do not use the (cd /var/www/html ) folder because in that folder only the webpage to read-only we can not run or do not run any other option.

Now create an API file (Application programming interface) file which we will access without any login ID and password

Create a file with the help of the gedit cmd

STEP TO RUN API PROPERLY WITHOUT AN ERROR:
* we have network connectivity and IP address
* Then move inside cd /var/www/cgi-bin/ this folder
* Then we will convert it into executable mode by #chmod +x file_name
* #!/usr/bin/python
remember to put the path
* print(“content-type:text/html\n\n”) don’t forget to add “\n” in the last of the statement

Now, write the code in your code file

The first line of the code file starts with “#!” , it is known as she-bang or hash-bang
The purpose of shebang or hash-bang is for the script to recognize the interpreter type when you want to execute the script from the shell. Mostly, and not always, you execute scripts by supplying the interpreter externally
If help to run the code file in which interpreter

after that, you will give the path of the python interpreter by running the cmd
# which python3 to know the location of that application…

TO convert the file into the executable mode

Paste the location of that python3 in front of that she-bang or hash-bang

The next line is :
Print(“content-type:text/html\n\n”)
This line is important to run the file in a browser other it will raise an error
Its function is that it helps to tell the browser the code file is in which format so that the browser run or execute the file (for e.g: file may be video, audio, image, text file, etc) so how the browser judge it by self so that why we add the content type line in our code file to tell the browser which type of the file

In the last of the content-type line, we will always mention to the \n because other the browser don’t judge the content type block because this block is known as the header block web-browser find the header block and judge the content type

After that, we will print some messages on the screen for the user and some package import and use that package to run some OS-based cmd…

Now finally, your API build and the time comes to run without the login and password or remote access or local access
we have only the connectivity of the network in between and know the IP address…

TYPE in your URL bar
http://192.168.2.109/cgi-bin/test_api.py
format “http://IP_address/cgi-bin/api-file-name.extension”

The output of the API file is :

Yeah, I completed that task
HURRAY…….GOODBYE……


If you have tried this and have some problem then DM me on WhatsApp at any time I am with you to resolve your query 7453010168

(VISHU GOYAL)
FOLLOW ME on linked-in
https://www.linkedin.com/in/vishu-goyal-4320581b9/

--

--

Vishugoyal

I am pursiing B-tech. and also very fond of learning new technology under the guidance of Vimal Daga sir (World Record Holder).