ne0trace Posted October 1, 2008 Share Posted October 1, 2008 (edited) Hello, we are currently using a program which has a serious bug. Sometimes it won't recognize the name of the computer as the name of the server (a client program). If that happens you have to manually change the name into the ip adress. This is only a temporary solution as we use a DHCP server. So my thought was to replace a certain string in the text "<ServerName>slved_p08x0010</ServerName>" (without the quotes) with the actual ip adress. But the ServerName variable can be different with every computer (can be an IP or a name). As some computers may have their cable plugged into a different adapter, it would be nice to have some check that only ip adresse like 192.168.x.x apply. I did some tests (with @IPAddress1) but nothing that could be called a productive code. So if anyone could give me a hint on achieving this, I would be very happy. Btw. I pasted the content of the XML file below. Thank you Felix expandcollapse popup<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <!DOCTYPE SystemConfiguration [ <!ELEMENT SystemConfiguration (GeneralCfg*, TimerCfg*, LogCfg*, AppDetails*)> <!ELEMENT GeneralCfg (ManagerPort, MaxBlockSize, NetworkMask)> <!ELEMENT ManagerPort (#PCDATA)> <!ELEMENT MaxBlockSize (#PCDATA)> <!ELEMENT NetworkMask (#PCDATA)> <!ELEMENT TimerCfg (AckTimeout, AckRetries, FastTimeout)> <!ELEMENT AckTimeout (#PCDATA)> <!ELEMENT AckRetries (#PCDATA)> <!ELEMENT FastTimeout (#PCDATA)> <!ELEMENT LogCfg (LogError, LogWarning, LogInfo, LogDebug, LogDebugex)> <!ELEMENT LogError (#PCDATA)> <!ELEMENT LogWarning (#PCDATA)> <!ELEMENT LogInfo (#PCDATA)> <!ELEMENT LogDebug (#PCDATA)> <!ELEMENT LogDebugex (#PCDATA)> <!ELEMENT AppDetails ANY> ]> <SystemConfiguration> <GeneralCfg> <ManagerPort>3234</ManagerPort> <ServerPort>3233</ServerPort> <MaxBlockSize>128000</MaxBlockSize> <NetworkMask>255.255.255.0</NetworkMask> <HttpRedirection>http://www.discreet.com</HttpRedirection> </GeneralCfg> <TimerCfg> <AckTimeout>20000</AckTimeout> <AckRetries>6</AckRetries> <FastTimeout>4000</FastTimeout> </TimerCfg> <LogCfg> <LogError>1</LogError> <LogWarning>1</LogWarning> <LogInfo>1</LogInfo> <LogDebug>0</LogDebug> <LogDebugex>0</LogDebugex> <LogMaxFileSize>10485760</LogMaxFileSize> </LogCfg> <AppDetails> <ServerSettings> <ManagerName>bb_manager</ManagerName> <AutoSearch>0</AutoSearch> [b] <ServerName>slved_p08x0010</ServerName>[/b] <ServerMAC>001EC9FF02B7</ServerMAC> <Description></Description> </ServerSettings> <SrvGUISettings> <LogErrorScr>1</LogErrorScr> <LogWarningScr>1</LogWarningScr> <LogInfoScr>1</LogInfoScr> <LogDebugScr>0</LogDebugScr> <LogDebugexScr>0</LogDebugexScr> <LogScrSize>2048</LogScrSize> <WindowX>189</WindowX> <WindowY>16</WindowY> <WindowW>800</WindowW> <WindowH>600</WindowH> <FontSize>2</FontSize> <AutoScroll>1</AutoScroll> <FirstTime>0</FirstTime> <TimeStamp>No</TimeStamp> <DateStamp>No</DateStamp> <ConfirmExit>1</ConfirmExit> </SrvGUISettings> </AppDetails> </SystemConfiguration> Edited October 1, 2008 by ne0trace Link to comment Share on other sites More sharing options...
enaiman Posted October 1, 2008 Share Posted October 1, 2008 This might be helpful to see if the computer has an IP within 192.168. range: If StringInStr(@IPAddress1, "192.168.") Then MsgBox(0, "Computer IP", @IPAddress1) ElseIf StringInStr(@IPAddress2, "192.168.") Then MsgBox(0, "Computer IP", @IPAddress2) ElseIf StringInStr(@IPAddress3, "192.168.") Then MsgBox(0, "Computer IP", @IPAddress3) ElseIf StringInStr(@IPAddress4, "192.168.") Then MsgBox(0, "Computer IP", @IPAddress4) Else MsgBox (16, "IP Error", "None of your computer's IP is in 192.168.x.x range") EndIf SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script wannabe "Unbeatable" Tic-Tac-Toe Paper-Scissor-Rock ... try to beat it anyway :) Link to comment Share on other sites More sharing options...
ne0trace Posted October 1, 2008 Author Share Posted October 1, 2008 Great! So far this seems to work: If StringInStr(@IPAddress1, "192.168.") Then $Ip = @IPAddress1 ElseIf StringInStr(@IPAddress2, "192.168.") Then $Ip = @IPAddress2 ElseIf StringInStr(@IPAddress3, "192.168.") Then $Ip = @IPAddress3 ElseIf StringInStr(@IPAddress4, "192.168.") Then $Ip = @IPAddress4 Else MsgBox(16, "IP Error", "None of your computer's IP is in 192.168.x.x range") EndIf MsgBox(0, "Computer IP", $Ip) Thank you Link to comment Share on other sites More sharing options...
ne0trace Posted October 1, 2008 Author Share Posted October 1, 2008 (edited) So I am nearly done but the StringReplace doesn't work with Wildcards... Any idea? expandcollapse popup#cs ---------------------------------------------------------------------------- AutoIt Version: 3.2.12.1 Author: myName Script Function: Template AutoIt script. #ce ---------------------------------------------------------------------------- ; Script Start - Add your code below here $XMLfile = "c:\test.xml" If Not FileExists("c:\test.xml") Then MsgBox(16, "Backburner XML Fix", "No Backburner file exists", 5) Else FileCopy($XMLfile, "c:\test.bak") EndIf If StringInStr(@IPAddress1, "192.168.") Then $Ip = @IPAddress1 ElseIf StringInStr(@IPAddress2, "192.168.") Then $Ip = @IPAddress2 ElseIf StringInStr(@IPAddress3, "192.168.") Then $Ip = @IPAddress3 ElseIf StringInStr(@IPAddress4, "192.168.") Then $Ip = @IPAddress4 Else MsgBox(16, "IP Error", "None of your computer's IP is in 192.168.x.x range") EndIf $Rawtext = FileRead($XMLfile) $Outputtext = StringReplace($Rawtext, "<ServerName>*</ServerName>", "<ServerName>" & $Ip & "</ServerName>") FileDelete($XMLfile) FileWrite($XMLfile, $Outputtext) Edited October 1, 2008 by ne0trace Link to comment Share on other sites More sharing options...
enaiman Posted October 1, 2008 Share Posted October 1, 2008 (edited) 2 ways to get this done: - use of an xml UDF (search for xml in Example Scripts Forum) - string split using "ServerName>" as delimiter Using the 2nd method the return will be "yourtextHere</" #Include <Array.au3> $String = "uy7r8346 75 34 <ServerName> My Computer </ServerName>kfdhgjk78 dfgn 8dg dfio" $IP = "192.168.0.100" $temp = StringSplit($String, "ServerName>", 1) _ArrayDisplay($temp) $computerName = StringTrimRight($temp[2], 2) MsgBox(0, "Computer Name", $computerName) $output = StringReplace($String, $computerName, $IP) MsgBox(0, "New String", $output) I've left the debugging lines inside to show you what happens. You only need to "adapt" this code to suit your script Edited October 1, 2008 by enaiman SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script wannabe "Unbeatable" Tic-Tac-Toe Paper-Scissor-Rock ... try to beat it anyway :) Link to comment Share on other sites More sharing options...
ne0trace Posted October 1, 2008 Author Share Posted October 1, 2008 Hey enaiman, I didn't have time to implement your code but it looks great. I was really excited to check out your approach with splitting teh strings. I hope to get it working this evening. Thanks so far Felix Link to comment Share on other sites More sharing options...
enaiman Posted October 1, 2008 Share Posted October 1, 2008 Welcome buddy I know you will get it working. SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script wannabe "Unbeatable" Tic-Tac-Toe Paper-Scissor-Rock ... try to beat it anyway :) Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now