WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: netstat problem  (Read 3791 times)

Offline wolf_core

  • Jr. Member
  • **
  • Posts: 69
netstat problem
« on: June 21, 2012, 05:01:24 AM »
Hi, I have a script that use netstat to get a value ad assign it to the variable "IP".

Code: [Select]
IP=`netstat -n -t | awk '{print $4}' | grep -o "[0-9]*\.[0-9]*\.[0-9]*\.[0-9]*" | grep -v "127.0.0.1" | sort -u`
I have installed net-tools to get netstat working but if I type in console
Code: [Select]
netstat -n -t no value returned because

Code: [Select]
tc@box:~$ netstat -n -t
Active Internet connections (w/o servers)
Proto Recv-Q Send-Q Local Address Foreign Address State
tc@box:~$

The network connection works fine, but no ip addres is shown. Can you help me.

Thanks in advance Luca
« Last Edit: June 21, 2012, 05:18:12 AM by wolf_core »

Offline tinypoodle

  • Hero Member
  • *****
  • Posts: 3857
Re: netstat problem
« Reply #1 on: June 21, 2012, 05:41:23 AM »
Neither clear in what aspect there would be a netstat problem nor how this would be related to TC Base...

What happens if you use 'busybox netstat' instead?
what does 'ifconfig |grep inet' give?
"Software gets slower faster than hardware gets faster." Niklaus Wirth - A Plea for Lean Software (1995)

Offline wolf_core

  • Jr. Member
  • **
  • Posts: 69
Re: netstat problem
« Reply #2 on: June 21, 2012, 06:35:47 AM »
Ty tinypoodle, the system say

Code: [Select]
tc@box:~$ busybox netstat
Active Internet connections (w/o servers)
Proto Recv-Q Send-Q Local Address Foreign Address State
netstat:/proc/net/tcp6: no such file or directory

tc@box:~$ ifconfig |grep inet
inet addr:192.168.1.144 Bcast:192.168.1.255 Mask:255.255.255.0
inet addr:127.0.0.1 Mask:255.0.0.0
tc@box:~$




Offline curaga

  • Administrator
  • Hero Member
  • *****
  • Posts: 11022
Re: netstat problem
« Reply #3 on: June 21, 2012, 06:45:33 AM »
Well, empty output is expected if you have no connections open. If you need the local IP without opening a connection somewhere you should use ifconfig or ip.
The only barriers that can stop you are the ones you create yourself.

Offline tinypoodle

  • Hero Member
  • *****
  • Posts: 3857
Re: netstat problem
« Reply #4 on: June 21, 2012, 10:43:16 AM »
Well, empty output is expected if you have no connections open. If you need the local IP without opening a connection somewhere you should use ifconfig or ip.

QED ;)
"Software gets slower faster than hardware gets faster." Niklaus Wirth - A Plea for Lean Software (1995)

Offline wolf_core

  • Jr. Member
  • **
  • Posts: 69
Re: netstat problem
« Reply #5 on: June 21, 2012, 11:29:46 AM »
I have launched netstat command while the system download same packages form repository but non ip is shown  :'( . How i can open  a temporary connection to obtain the IP from nestat command. The php script use this IP to compose a session password used in some page as security system.

Thanks Luca

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11500
Re: netstat problem
« Reply #6 on: June 21, 2012, 11:43:11 AM »
Hi wolf_core
If you SSH into another machine or mount a remote drive, that will do it. Or you could change:
Code: [Select]
[P=`netstat -n -t | awk '{print $4}' | grep -o "[0-9]*\.[0-9]*\.[0-9]*\.[0-9]*" | grep -v "127.0.0.1" | sort -u`to:
Code: [Select]
IP=`ifconfig  | awk '{print $2}' | grep -o "[0-9]*\.[0-9]*\.[0-9]*\.[0-9]*"`

Offline wolf_core

  • Jr. Member
  • **
  • Posts: 69
Re: netstat problem
« Reply #7 on: June 21, 2012, 01:13:20 PM »
Thanks Rich ;D the code you have posted put correct IP in the variable. 
Code: [Select]
IP=`ifconfig  | awk '{print $2}' | grep -o "[0-9]*\.[0-9]*\.[0-9]*\.[0-9]*" | grep -v "127.0.0.1"`.

Thanks again for your help
 

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11500
Re: netstat problem
« Reply #8 on: June 21, 2012, 01:21:13 PM »
Hi wolf_core
You are welcome. Bear in mind, if this script actually expects to find an open connection because the IP variable
is set, it could fail elsewhere. You didn't mention where the script came from or what it does, so I though I should
point that out.

Offline wolf_core

  • Jr. Member
  • **
  • Posts: 69
Re: netstat problem
« Reply #9 on: June 21, 2012, 01:39:22 PM »
Hi Rich, the script is 123Aurora a WEB solar logger,  it is made to work with PogoPlug running ArchLinux but I try to use it on my DT166 Microserver running Tiny Core.
I think that there is another problem somewhere because i can't login, but now I can see the login page, so I return to the old code
Code: [Select]
P=`netstat -n -t | awk '{print $4}' | grep -o "[0-9]*\.[0-9]*\.[0-9]*\.[0-9]*" | grep -v "127.0.0.1" | sort -u` ad use cherokee for opening temp connections so netstat -n -t show some values.

Thanks Luca
« Last Edit: June 22, 2012, 03:38:16 AM by wolf_core »