How to echo images Urls from a wordpress post, that are relally in the post

I have a question.

I use the following code to output the image URLs of a wordpress post. The image URLs are related to the “attached images” of a wordpress post and not the ones that are actually used in the post.

If you added an image to a post 2 years ago, but currently don’t use the image anymore, the old unused Image Url will still be output via the code. I would like to avoid this.

What i need to do to adjust the code to output only those Image URLs that are really in the source code of the post or really actually used in the post? That can be also Images that are attached to another wordpress post.