Author Topic: [SH] Display IP!  (Read 4649 times)

0 Members and 2 Guests are viewing this topic.

Offline Joe

  • B&
  • Moderator
  • Hero Member
  • *****
  • Posts: 10319
  • In Soviet Russia, text read you!
    • View Profile
    • Github
[SH] Display IP!
« on: October 27, 2005, 08:36:40 pm »
Code: [Select]
wget -q http://www.javaop.com/~joe/ip.php
cat ip.php
rm ip.php
echo ' '

Could have written it yourself. Eat me. =).
I'd personally do as Joe suggests

You might be right about that, Joe.


Offline iago

  • Leader
  • Administrator
  • Hero Member
  • *****
  • Posts: 17914
  • Fnord.
    • View Profile
    • SkullSecurity
Re: [SH] Display IP!
« Reply #1 on: October 27, 2005, 08:58:40 pm »
I actually set up a script to do that based on a website.  Hmm, wonder if I still have it..

yep!

IP=`curl -s www.whatismyip.com | grep -i "<title" | cut -d\  -f 5`

<edit> by the way, you might want to do some error handling in yours"

Code: [Select]
if wget -q http://www.javaop.com/~joe/ip.php; then
  cat ip.php
  rm ip.php
  echo ' '
else
  echo "Failed to retrieve ip..."
fi

that's untested, but it should work. 

or

Code: [Select]
wget -q http://www.javaop.com/~joe/ip.php
if [ -f ip.php ]; then
  cat ip.php
  rm ip.php
  echo ' '
else
  echo "Failed"
fi

Again, untested :)

Also, I would recommend using a temporary file, like /tmp/ip.php. 
« Last Edit: October 27, 2005, 09:02:08 pm by iago »

Offline Joe

  • B&
  • Moderator
  • Hero Member
  • *****
  • Posts: 10319
  • In Soviet Russia, text read you!
    • View Profile
    • Github
Re: [SH] Display IP!
« Reply #2 on: October 27, 2005, 10:59:28 pm »
I stuck this in /usr/bin, so now in JavaOp I can just do /run getip. Problem though, wget outputs a single blank line, so it shows as

#1:
#1: IP

I do wget -q so it doesn't output anything, but it still outputs that line. Anykne know how to stop that?
I'd personally do as Joe suggests

You might be right about that, Joe.


Offline Newby

  • Moderator
  • Hero Member
  • *****
  • Posts: 10877
  • Thrash!
    • View Profile
Re: [SH] Display IP!
« Reply #3 on: October 27, 2005, 11:13:45 pm »
wget -q thatwebpage &> /dev/null

Something along those lines.
- Newby
http://www.x86labs.org

Quote
[17:32:45] * xar sets mode: -oooooooooo algorithm ban chris cipher newby stdio TehUser tnarongi|away vursed warz
[17:32:54] * xar sets mode: +o newby
[17:32:58] <xar> new rule
[17:33:02] <xar> me and newby rule all

I'd bet that you're currently bloated like a water ballon on a hot summer's day.

That analogy doesn't even make sense.  Why would a water balloon be especially bloated on a hot summer's day? For your sake, I hope there wasn't too much logic testing on your LSAT. 

Offline Joe

  • B&
  • Moderator
  • Hero Member
  • *****
  • Posts: 10319
  • In Soviet Russia, text read you!
    • View Profile
    • Github
Re: [SH] Display IP!
« Reply #4 on: October 27, 2005, 11:26:33 pm »
<3 newby.

EDIT -
Interestingly enough, it didn't work.
« Last Edit: October 27, 2005, 11:28:45 pm by Joe[e2] »
I'd personally do as Joe suggests

You might be right about that, Joe.


Offline iago

  • Leader
  • Administrator
  • Hero Member
  • *****
  • Posts: 17914
  • Fnord.
    • View Profile
    • SkullSecurity
Re: [SH] Display IP!
« Reply #5 on: October 28, 2005, 08:43:36 am »
Firstly, figure out which line is outputting the blank line.  Are you sure it's the wget?

Try

wget ... > /dev/null 2>&1

Offline Joe

  • B&
  • Moderator
  • Hero Member
  • *****
  • Posts: 10319
  • In Soviet Russia, text read you!
    • View Profile
    • Github
Re: [SH] Display IP!
« Reply #6 on: November 04, 2005, 05:08:22 pm »
Unless cat is outputting a blank line (which it doesn't, from my experience with it), it has to be wget, because cat outputs the IP on the second line, and wget is the only thing before it.

@code: /test

EDIT -
Wow.
Code: [Select]
joe@JoeMomma:~/dev/java/rps $ getip

172.129.223.201
I'd personally do as Joe suggests

You might be right about that, Joe.


Offline iago

  • Leader
  • Administrator
  • Hero Member
  • *****
  • Posts: 17914
  • Fnord.
    • View Profile
    • SkullSecurity
Re: [SH] Display IP!
« Reply #7 on: November 04, 2005, 05:54:47 pm »
When running your script, direct stdout (>) and stderr (2>) to /dev/null.  See which one gets rid of the blank line.