I want to create a network hub with the help of raspberry pi for connecting 2 standalone devices with the hub and then provide internet to the hub so that both the devices can access the internet individually.
In any case,I want to use my pi as a network hub. Is it possible? If yes then how?
No. There is no way software would be fast enough to handle the Ethernet protocol. You need dedicated hardware to handle the bus.
If you need more LAN interfaces, the best solution in terms of performance per dollar is to get several USB to LAN adapters.
For low speeds (below 10Mbps), an SPI to LAN module can be used. Such a module can indeed be wired to GPIO SPI pins. You will want to check if a Linux driver is available before buying a module, since many of those are made for Arduino and may lack Linux support.
Also, you may want to take a look at Banana Pi R1. It’s quite old by now, and you’ll have to install a Banana Pi specific distro (Bananian or Armbian), but it’s a good option for a hub/NAS project.
Definitely NOT – for a start Ethernet uses galvanically isolated differential signalling.