English Amiga Board


Go Back   English Amiga Board > Coders > Coders. System > Coders. Scripting

 
 
Thread Tools
Old 26 January 2023, 23:52   #1
shelter
Registered User
 
Join Date: Nov 2022
Location: #Amigaland
Posts: 156
How do I get the IP from this output?

I've been trying to find some information on how to "parse" text, I usually manage to figure things out but not this time.
I just want the IP from roadshow, all I've found is ShowNetStatus which outputs this:

Network status summary
Local host address = 192.168.100.13 (on interface 'Prism2')
Default gateway address = 192.168.100.1
Domain name system servers = 192.168.100.1, 192.168.100.1

But how do I script so it just outputs the IP (host address)?

Last edited by shelter; 27 January 2023 at 14:14.
shelter is offline  
Old 27 January 2023, 20:52   #2
tygre
Returning fan!
 
tygre's Avatar
 
Join Date: Jan 2011
Location: Montréal, QC, Canada
Posts: 1,434
Hi Shelter!

Maybe you could write your own program (in C?) that could output only your IP address or use something like this?

Cheers!
tygre is offline  
Old 27 January 2023, 20:58   #3
Retro1234
Phone Homer
 
Retro1234's Avatar
 
Join Date: Jun 2006
Location: 5150
Posts: 5,773
Is there a way to parse it through 'Type' or something so it outputs the first line only?
Retro1234 is offline  
Old 27 January 2023, 21:55   #4
mfilos
Paranoid Amigoid
 
mfilos's Avatar
 
Join Date: Mar 2008
Location: Athens/Greece
Age: 45
Posts: 1,978
You can use GetIP (AmiTCP, Miami, RoadShow) or GetIPAddress (For everything + WinUAE) from Flype's GitHub
https://github.com/flype44/AmigaOS

mfilos is offline  
Old 27 January 2023, 22:36   #5
shelter
Registered User
 
Join Date: Nov 2022
Location: #Amigaland
Posts: 156
Wow. I searched for such a program but I don't find any. Thanks.
I actually thought about writing something myself but I don't know C that well.
shelter is offline  
Old 28 January 2023, 14:24   #6
daxb
Registered User
 
Join Date: Oct 2009
Location: Germany
Posts: 3,303
Here a ShowNetStatus ARexx script version without error checking just for the record:
Code:
/* Get the IP from ShowNetStatus */

ADDRESS COMMAND

'ShowNetStatus >RAM:tempout'

CALL OPEN('tempfile', 'RAM:tempout', 'R')
CALL READLN('tempfile')
str = READLN('tempfile')    /* read the second line */
CALL CLOSE('tempfile')
PARSE VAR str . . . . ip .    /* get the fifth word */
SAY ip
'delete RAM:tempout'

Last edited by daxb; 29 January 2023 at 20:40.
daxb is offline  
Old 29 January 2023, 18:11   #7
mfilos
Paranoid Amigoid
 
mfilos's Avatar
 
Join Date: Mar 2008
Location: Athens/Greece
Age: 45
Posts: 1,978
It needs one more dot on that line:
PARSE VAR str . . . . ip . /* get the fifth word */

cause you get the " = " in output (at least on my 3.2.1 setup).

Also deleting the RAM:tempout gives an error that is in use.
I even put a delay of 1 sec and still same.
if you delete outside the script it works just fine... weird
mfilos is offline  
Old 29 January 2023, 20:46   #8
daxb
Registered User
 
Join Date: Oct 2009
Location: Germany
Posts: 3,303
Thanks for testing and correction! Such things happen if you don't test it. The missing dot must be ate by Pacman. For the missing CLOSE() I haven't an excuse. However, fixed it. Should work now.
daxb is offline  
Old 29 January 2023, 21:14   #9
mfilos
Paranoid Amigoid
 
mfilos's Avatar
 
Join Date: Mar 2008
Location: Athens/Greece
Age: 45
Posts: 1,978
Yep it should be fine.
I don’t know arexx but learning slowly although I remembered from other languages you need to close the file cause on delete is still open
mfilos is offline  
Old 29 January 2023, 22:26   #10
idrougge
Registered User
 
Join Date: Sep 2007
Location: Stockholm
Posts: 4,332
If you use PIPE: for output and input, you won't have to deal with deletion or closing files.
idrougge is offline  
Old 07 February 2023, 12:55   #11
shelter
Registered User
 
Join Date: Nov 2022
Location: #Amigaland
Posts: 156
Thanks, here's something simple I wrote for GetIP to put the IP in environment variables.
Code:
set IP `GetIP`
; Outputs IP: <yourip>
setenv net_txtip "IP:" `get IP`
; Outputs <yourip>
setenv net_ip `get IP`
But the ARexx code might be better since it doesn't rely on GetIP, just ShowNetStatus which comes with RoadShow.
shelter is offline  
Old 07 February 2023, 13:33   #12
mfilos
Paranoid Amigoid
 
mfilos's Avatar
 
Join Date: Mar 2008
Location: Athens/Greece
Age: 45
Posts: 1,978
I use that for displaying my IP on the titlebar as well

Code:
FailAt 21
C:GetIPAddress >ENV:IP
If Warn
  Echo "" >ENV:IPBar
Else
  Echo "IP: $IP" >ENV:IPBar
EndIf
I always display the IPBar variable. If no network stack is online, nothing is shown. If yes, then the IP: xxx.xxx.xxx.xxx is shown

This is a script on S: that I execute everytime on Network-Startup and Network-Shutdown script so I always have the correct IP on titlebar
mfilos is offline  
Old 03 March 2023, 15:03   #13
EctoOne
Registered User
 
EctoOne's Avatar
 
Join Date: Jun 2020
Location: Germany
Posts: 370
Does anyone know an alternative for uae4arm (android)?

I've tried the tools mfilos linked but it seems that uae4arm is too old and therefore doesn't has the required flag.

From the GetIPAddress source:
Quote:
For now, this wont work on the UAE TCP/IP implementation,
because it does not handle the ioctl() flag "SIOCGIFCONF".
EctoOne is offline  
 


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Similar Threads
Thread Thread Starter Forum Replies Last Post
Output to CLI REAKTOR BEAR Coders. Asm / Hardware 8 29 September 2022 11:03
CRT Tv Output Leandro Jardim support.WinUAE 8 24 May 2013 14:54
output delay? jharrison support.WinUAE 16 01 February 2009 23:16
output problem :( RickyC support.WinUAE 8 16 July 2008 23:36
COMP output Enverex support.Hardware 19 16 February 2004 19:53

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 09:33.

Top

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Page generated in 0.15662 seconds with 15 queries