You are not logged in.

#1 2009-10-10 14:08:59

RedArcher
Member
From: South Africa
Registered: 2009-09-03
Posts: 115

[SOLVED] Retrive (only) your IP Address from any page

EDIT: original title: Retrive your IP Adress Via 10.138 (http://10:138) with WGET | GREP

This is more related to Conky, which is, in a way, scripting-like (amateur scripting), so here goes...

Well, I'm using D-Link router and I just wish to get my IP Address from it instead of:

${execi 300 wget www.whatismyip.com/automation/n09230945.asp -O - -q}

or

${wget http://checkip.dyndns.org/ -q -O - | grep -Eo '\<[[:digit:]]{1,3}(\.[[:digit:]]{1,3}){3}\>'}

I want it from the following address:
http://10.138/wancfg.cmd?action=view

wget --no-cookies --no-cache http://10.138/wancfg.cmd?action=view --http-user=user --http-password=user -O - -q

or even

wget --no-cookies --no-cache http://user:user@10.138/wancfg.cmd?action=view -O - -q

but what to insert after wget | grep ??? (I tried -n 44 without success)

this is the code:

<html><head>
<link rel=stylesheet href='stylemain.css' type='text/css'>
<link rel=stylesheet href='colors.css' type='text/css'>
<meta http-equiv='refresh' content='5'>
<meta HTTP-EQUIV='Pragma' CONTENT='no-cache'>
<title></title>
</head>
<body>
<blockquote>
<form>
<b>WAN Info</b><br><br>
<table border='1' cellpadding='4' cellspacing='0'>
   <tr align='center'>
      <td class='hd'>Port/VPI/VCI</td>

      <td class='hd'>VLAN Mux</td>
      <td class='hd'>Con. ID</td>
      <td class='hd'>Category</td>
      <td class='hd'>Service</td>
      <td class='hd'>Interface</td>
      <td class='hd'>Protocol</td>

      <td class='hd'>Igmp</td>
      <td class='hd'>QoS</td>
      <td class='hd'>State</td>
      <td class='hd'>Status</td>
      <td class='hd'>IP Address</td>
   </tr>

   <tr align='center'>
      <td>0/8/48</td>
      <td>Off</td>
      <td>1</td>
      <td>UBR</td>
      <td>pppoe_0_8_48_1</td>

      <td>ppp_0_8_48_1</td>
      <td>PPPoE</td>
      <td>Disabled</td>
      <td>Disabled</td>
      <td>Enabled</td>
      <td>Up</td>

      <td>--- HERE'S THE IP ADDRESS ---</td>
   </tr>
   <tr align='center'>
      <td>0/8/35</td>
      <td>Off</td>
      <td>1</td>
      <td>UBR</td>

      <td>br_0_8_35</td>
      <td>nas_0_8_35</td>
      <td>Bridge</td>
      <td>N/A</td>
      <td>Disabled</td>
      <td>Enabled</td>

      <td>Up</td>
      <td>&nbsp</td>
   </tr>
</table>
<br><br><b>PPTP Info</b><br><br>
<table border='1' cellpadding='4' cellspacing='0'>
   <tr align='center'>
      <td class='hd'>IP Address</td>
      <td class='hd'>Gateway</td>

</tr>
   <tr align='center'>
      <td>&nbsp</td>
      <td>&nbsp</td>
</tr>
</table>
</form>
</blockquote>
</body>
</html>

Last edited by RedArcher (2009-11-07 15:50:22)

Offline

#2 2009-10-10 14:37:59

RedArcher
Member
From: South Africa
Registered: 2009-09-03
Posts: 115

Re: [SOLVED] Retrive (only) your IP Address from any page

Well well well... what do you know:

wget --no-cookies --no-cache http://user:user@10.138/wancfg.cmd?action=view -O - -q

WORKS!!!

Can I be much more silly than I am now??? tongue


Please, can someone, briefly, explain this command:

grep -Eo '\<[[:digit:]]{1,3}(\.[[:digit:]]{1,3}){3}\>'

Anyhow, can someone, please, post here another way, and explain what each Letter/Command does what wink

Last edited by RedArcher (2009-10-10 14:41:41)

Offline

#3 2009-10-10 15:48:38

Trent
Member
From: Baltimore, MD (US)
Registered: 2009-04-16
Posts: 990

Re: [SOLVED] Retrive (only) your IP Address from any page

I'm going from memory here, so I might get one or two things wrong.

\< and \> are word boundaries -- they will pick up e.g. 127.0.0.1 if it is by itself, but not 181203.1211111.23.43.4332242224.6729 which would otherwise match.  "word" is any sequence of characters a-z, A-Z, 0-9, and underscore IIRC.
[[:digit:]] is a character class that just says to match any digit -- characters 0-9.
{1,3} is a quantifier that says "match the last thing at least once, but try to match it up to three times."  Similarly, {3} is a quantifier that says "match the last thing exactly three times".
The parentheses are for grouping; the {3} quantifier refers to the entire subpattern in parentheses.
A dot . usually matches any character except newline.  The backslash makes it a literal . so it only matches, well, dots.

So this pattern says:
Match a word boundary, followed by one to three digits, followed by (a dot, followed by one to three digits) three times, followed by a word boundary.

Make sense?

Offline

Board footer

Powered by FluxBB