Writing a script to get both URL and IP information


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Writing a script to get both URL and IP information
# 1  
Old 02-04-2010
Writing a script to get both URL and IP information

hi guys- im trying to write a script to get both url and ip information. i think i can get it to work if i hardcode the url into the script, however what I rather have happen is the script ask the user to input a url. ive searched through the wget man and cant find anything there. i know this must be an easy fix, can anyone help?

ill try to break out what i think should happen

#!/bin/bash
wget (dont want to hardcode the url here, i want a prompt to go to user for url)
save url data to a file
read url from file to obtain ip address

i would like to use this so i can easily download a webpage and get its ip in one step

any help would be greatly appreciated

Last edited by doggydog2002; 02-04-2010 at 06:36 AM..
# 2  
Old 02-04-2010
If you just want the IP address of a host, why don't you use host(1) or dig(1) ? Why wget ?
# 3  
Old 02-04-2010
well..

im hoping to get all of the url's information as well as the ip all in one scrippt
# 4  
Old 02-04-2010
Code:
#!/bin/sh

read url
wget $url
host $(echo ${url#*//} | sed 's/\/.*//')

# 5  
Old 02-04-2010
ill try

ill try this code out and see if it works for me.. thanks a lot for the code.

would anyone be able to detail exactly what each line is doing for me in easy to understand terms? i know what read, wget, and those things mean by definition, but knowing what they mean in real terms would help a lot.
# 6  
Old 02-06-2010
Code:
read url

Read user input, the url, into the variable named 'url'.

Code:
wget $url

Fetch the contents of the url.

Code:
host $(echo ${url#*//} | sed 's/\/.*//')

echo ${url#*//} - removes the 'http://' part from the url, if any.
sed 's/\/.*//' - removes the file path from the url

Only the host name remains which is passed onto host(1) to get the IP.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to detect url in use in a script?

Hello, I have a small script and it runs from web application in below format: pipe:///path_to_myscript.sh url1 url2 url3 myscript.sh: #!/bin/bash count=0 while do count=$((count+1)) exec 3>&1 ((ffmpeg -i $1 ...... -f mpegts pipe:1 2>/dev/null 1>&3 ) 2>&1 | \ while read LINE; do echo... (9 Replies)
Discussion started by: baris35
9 Replies

2. Shell Programming and Scripting

Reading URL using Mechanize and dump all the contents of the URL to a file

Hello, Am very new to perl , please help me here !! I need help in reading a URL from command line using PERL:: Mechanize and needs all the contents from the URL to get into a file. below is the script which i have written so far , #!/usr/bin/perl use LWP::UserAgent; use... (2 Replies)
Discussion started by: scott_cog
2 Replies

3. UNIX for Dummies Questions & Answers

Awk: print all URL addresses between iframe tags without repeating an already printed URL

Here is what I have so far: find . -name "*php*" -or -name "*htm*" | xargs grep -i iframe | awk -F'"' '/<iframe*/{gsub(/.\*iframe>/,"\"");print $2}' Here is an example content of a PHP or HTM(HTML) file: <iframe src="http://ADDRESS_1/?click=5BBB08\" width=1 height=1... (18 Replies)
Discussion started by: striker4o
18 Replies

4. Shell Programming and Scripting

reading a file extracting information writing to a file

Hi I am trying to extract information out of a file but keep getting grep cant open errors the code is below: #bash #extract orders with blank address details # # obtain the current date # set today to the current date ccyymmdd format today=`date +%c%m%d | cut -c24-31` echo... (8 Replies)
Discussion started by: Bruble
8 Replies

5. Shell Programming and Scripting

script to call url

how to call url using unix script (2 Replies)
Discussion started by: HemaV
2 Replies

6. Web Development

Regex to rewrite URL to another URL based on HTTP_HOST?

I am trying to find a way to test some code, but I need to rewrite a specific URL only from a specific HTTP_HOST The call goes out to http://SUB.DOMAIN.COM/showAssignment/7bde10b45efdd7a97629ef2fe01f7303/jsmodule/Nevow.Athena The ID in the middle is always random due to the cookie. I... (5 Replies)
Discussion started by: EXT3FSCK
5 Replies

7. Shell Programming and Scripting

url calling and parameter passing to url in script

Hi all, I need to write a unix script in which need to call a url. Then need to pass parameters to that url. please help. Regards, gander_ss (1 Reply)
Discussion started by: gander_ss
1 Replies

8. UNIX for Advanced & Expert Users

url calling and parameter passing to url in script

Hi all, I need to write a unix script in which need to call a url. Then need to pass parameters to that url. please help. Regards, gander_ss (1 Reply)
Discussion started by: gander_ss
1 Replies

9. UNIX for Dummies Questions & Answers

Accessing a URL through script

Hi, I am faced with a problem. Is it possible to access a URL from Unix script and to check whether it is up and running? I could find some perl scripts that can do the same , but could not get any info if we can achieve it with UNix. Any help will be very useful. Thanks in advance. (1 Reply)
Discussion started by: hamsasal
1 Replies
Login or Register to Ask a Question